public class MessageFormatCloneReturnIfUseDateFormatMap extends HashMap<String,MessageFormat>
StrutsのMessageResourcesは、キャッシュからgetしたMessageFormatを同期化せずに複数スレッドでアクセス可能にしている。
このバグを回避するため、キャッシュから同一インスタンスを返さず、cloneインスタンスを返すよう拡張している。
ただし、全てのMessageFormatを無条件にcloneするのではなく、
明らかにスレッドアンセーフ問題が発生する、DateFormatをサブフォーマットに持つMessageFormatのみ、
get時にcloneする。
このクラスは、StrutsのMessageResourcesのバグ回避専用クラスである。
putメソッド(null値の設定なし)とgetメソッドのみ使用されることを前提としている。
その他のメソッドを使用した場合の、Mapとしての動作は保証しない。
また、putの戻り値では、前回のputの引数で渡されたインスタンスではなく、等価なcloneインスタンスを返す場合がある。
(get時にcloneインスタンスを返す条件を満たすものがこれに該当する。)
| コンストラクタと説明 |
|---|
MessageFormatCloneReturnIfUseDateFormatMap() |
| 修飾子とタイプ | メソッドと説明 |
|---|---|
MessageFormat |
get(Object key)
キャッシュされたMessageFormatインスタンスを、必要に応じてcloneして返す。
|
MessageFormat |
put(String key,
MessageFormat value)
MessageFormatインスタンスをキャッシュする。
|
clear, clone, containsKey, containsValue, entrySet, isEmpty, keySet, putAll, remove, size, valuesequals, hashCode, toStringpublic MessageFormatCloneReturnIfUseDateFormatMap()
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.