public class MessageFormatCloneReturnMap extends HashMap<String,MessageFormat>
StrutsのMessageResourcesは、キャッシュからgetしたMessageFormatを同期化せずに複数スレッドでアクセス可能にしている。
このバグを回避するため、キャッシュから同一インスタンスを返さず、cloneインスタンスを返すよう拡張している。
また、MessageFormatで使用するサブフォーマットの中には、
(具体的には、{0,number}等の記述時に使用されるDecimalFormatが該当。)
cloneしなければスレッドセーフであるが、
format実行後にcloneすると、MessageFormatインスタンス(サブフォーマットのインスタンス含む)が
スレッドごとに存在するにも関わらず、スレッドアンセーフとなるものがある。
このクラスは、format実行前にputメソッドにMessageFormatインスタンスが渡される前提で、
putメソッド内にてcloneを行うことで、この問題を回避している。
このクラスは、StrutsのMessageResourcesのバグ回避専用クラスである。
putメソッド(null値の設定なし)とgetメソッドのみ使用されることを前提としている。
その他のメソッドを使用した場合の、Mapとしての動作は保証しない。
また、putの戻り値では、前回のputの引数で渡されたインスタンスではなく、等価なcloneインスタンスを返す。
コンストラクタと説明 |
---|
MessageFormatCloneReturnMap() |
修飾子とタイプ | メソッドと説明 |
---|---|
MessageFormat |
get(Object key)
キャッシュされたMessageFormatのcloneインスタンスを返す。
|
MessageFormat |
put(String key,
MessageFormat value)
MessageFormatインスタンスのcloneインスタンスをキャッシュする。
|
clear, clone, containsKey, containsValue, entrySet, isEmpty, keySet, putAll, remove, size, values
equals, hashCode, toString
public MessageFormat put(String key, MessageFormat value)
put
インタフェース内 Map<String,MessageFormat>
put
クラス内 HashMap<String,MessageFormat>
key
- MessageFormatキャッシュ時のキーvalue
- キャッシュするMessageFormatインスタンスpublic MessageFormat get(Object key)
get
インタフェース内 Map<String,MessageFormat>
get
クラス内 HashMap<String,MessageFormat>
key
- MessageFormatキャッシュ時のキーCopyright © 2014. All Rights Reserved.