Foren

Thread Safety in Singletons and Statics

thumbnail
Bijan Vakili, geändert vor 9 Jahren.

Thread Safety in Singletons and Statics

Expert Beiträge: 375 Beitrittsdatum: 10.03.09 Neueste Beiträge
Hi would you consider below thread-safe?
com.liferay.portlet.PortletContextFactory
Seems vulnerable to write-over-write
This is template of thread safety issue; same pattern can be found in more places; are we handling this issue somehow?


http://stackoverflow.com/questions/7048198/thread-safe-singletons-in-java
thumbnail
David H Nebinger, geändert vor 9 Jahren.

RE: Thread Safety in Singletons and Statics (Antwort)

Liferay Legend Beiträge: 14919 Beitrittsdatum: 02.09.06 Neueste Beiträge
It's like a servlet context, you get one (some) created at portlet startup. The context doesn't change during runtime. Sure it's not decorated with the synchronized keyword, but it should be just fine.
thumbnail
Bijan Vakili, geändert vor 9 Jahren.

RE: Thread Safety in Singletons and Statics

Expert Beiträge: 375 Beitrittsdatum: 10.03.09 Neueste Beiträge
Thanks David; agreed, it is a moot point. I reviewed portal-service and looks fine. Thanks for your prompt and insightful reply.