[PJUG Javamail] EJB and thread safety.
Michael Phoenix
michaelandrewphoenix at gmail.com
Mon Jan 5 14:15:42 EST 2009
I'm still relatively new to EJB and just discovered an interesting
situation that I would like some feedback on. I am saving a particular
value as an instance variable in an entiry bean (EJB 2.0). This
particulr bean is also used by another thread that is initiated by a
JMS message which is called in the middle of a particular method I
will call method x. I set the value of this instance variable before
calling the that sends the JMS message to initiate the thread. After
that is done, when I try to access the instance, I find that it has
been reset to its initial value . Method Y, which is called by the
message listener when it intercepts the JMS message creates another
instance of this entity bean, using the same database record that is
being used in method x. Method y actually does alter the instance
value, but curiously that is not the value that appears in the latter
part of method x. Method y also sets the value of container managed
properties for the bean in question.
I have resolved the immediate problem by simply resetting the instance
variable to the value I need after calling the JMS method, but I was
curious as to what was going on here. Weare making big changes to our
apps which may include going to EJB 3, so I was hoping some folks on
this list with more experience could discuss thread-safety issues of
EJB 2 and 3, particularly as it may relate to different threads
operating on different instances of an entity bean that represents the
same persistent data and JMS. Any information would be appreciated.
More information about the Javamail
mailing list