users@glassfish.java.net

Re: Container injected _at_Resource fields should be declared "volatile"?

From: <glassfish_at_javadesktop.org>
Date: Fri, 16 Nov 2007 07:22:16 PST

Could you share more details about this doc? It seems to me a over-generalization. It really depends on 2 factors: (1) if the target resource is immutable or not; and (2) how the respective containers handle thread-safety and manage the component lifecycle.

Most injectable resources are actually immutable such as javax.sql.DataSource, or javax.jms.Destination, etc. So they should already be thread safe.

In EJB (bean class or interceptors), component instances are not shared between threads. Web components may be shared by multiple threads and so more care is needed with field/setter injections for non-thread-safe resources. But I doubt if using volatile would solve it. Just my 2 cents.

-cheng
[Message sent by forum member 'cf126330' (cf126330)]

http://forums.java.net/jive/thread.jspa?messageID=245827