假设Spring MessageSource实现是线程安全的是否安全?

时间:2022-09-10 21:32:56

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

是否可以安全地假设org.springframework.context.MessageSource接口的所有实现在初始化后都是线程安全的?

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...

我希望它是安全的,但现在我正在查看Spring源代码,并且有org.springframework.context.support.ReloadableResourceBundleMessageSource,它不时重新加载属性,文档没有说明是否是线程安全的。 ..

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

编辑:似乎ReloadableResourceBundleMessageSource确实在需要的地方同步...但是我原来的问题仍然存在。

1 个解决方案

#1


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.

话虽如此,从你的应用程序的角度来看,脏读的危害是什么?错误的标签或消息值?您可能不必担心缺少值,因为如果修改了JSP或类以使用新消息,则必须重新部署整个应用程序。我觉得你在这里很安全。

#1


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.

话虽如此,从你的应用程序的角度来看,脏读的危害是什么?错误的标签或消息值?您可能不必担心缺少值,因为如果修改了JSP或类以使用新消息,则必须重新部署整个应用程序。我觉得你在这里很安全。