views:

586

answers:

1

Is it safe to assume that all implementations of org.springframework.context.MessageSource interface are thread-safe after initialization?

I would expect that it's safe, but now I'm looking through Spring source code, and there's org.springframework.context.support.ReloadableResourceBundleMessageSource which reloads properties from time to time, and documentation doesn't say anything about being thread-safe...

EDIT: It seems that ReloadableResourceBundleMessageSource indeed is synchronized where it needs to be... however my original question remains.

+2  A: 

Just looked at the source code - no synchronized keywords anywhere, and writable state. No, it's not thread-safe.

With that said, what's the harm of a dirty-read from your app's point of view? A wrong label or message value? You probably don't have to worry about a missing value, because you'd have to redeploy the whole app if JSPs or classes were modified to use new messages. I think you're pretty safe here.

duffymo
Check http://www.javaresearch.org/source/spring1.0.2/org/springframework/context/support/ReloadableResourceBundleMessageSource.java.html, it does synchronize on cachedProperties. Dirty reads are OK, exceptions are what I'm afraid of. Though you're right, shouldn't happen.
Domchi
Thank you, I missed that one. They were smart and kept the synchronized block as small as possible.
duffymo