Forums: Open Discussion (Thread #18986)

DatePropertyEditorRegistrarはスレッドセーフですか? (2008-06-12 02:39 by kidotaka #37116)

jp.terasoluna.fw.beans.DatePropertyEditorRegistrarは、デフォルト値の保持を意図してstaticにSimpleDateFormatを持っています。
新たにsetterからDateFormatが渡されない限り、static変数の参照がインスタンス変数にセットされていて、それを用いるはずです。

これはマルチスレッド上で、同じSimpleDateFormatのインスタンスを見ることがあるということではないのでしょうか?

SimpleDateFormatは確実にスレッドセーフではないクラス(JavaDocで同期化してねと書いてある。)ですが、この実装って本当に大丈夫なのですか?
デフォルトを用いる場合に危険なコードに見えました。

Reply to #37116×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: DatePropertyEditorRegistrarはスレッドセーフですか? (2008-06-27 16:52 by matsumotoa #37362)

ご指摘の通り、現在のコードでは、
「マルチスレッド上で、同じSimpleDateFormatのインスタンスを見ること」、そして、誤った日付が設定されてしまう事態が発生します。

現状では、
・DatePropertyEditorRegistrar内部で使用しているCustomDateEditorのgetAsTextとsetAsTextを同期化するように拡張して使う
・apache commonsのFastDateFormatをjava.text.DateFromatでラップして使う
などの対応が考えられます。

これは、Spring本家でも問題になっていますね。
TERASOLUNAとしては本家が落ち着くまで静観したほうがよいかもしれません。
http://jira.springframework.org/browse/SPR-4361
Reply to #37116

Reply to #37362×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login