-
1. Re: Stateless Session bean not thread safe?
lucluc May 3, 2002 6:54 PM (in response to lucluc)The code
-
2. Re: Stateless Session bean not thread safe?
scoy May 3, 2002 10:28 PM (in response to lucluc)Lets see. You have a stateless session bean, in which you are trying to maintain some state (nDemo). Can you see the problem with that?
Try making it a stateful bean and see if that works properly.
Even then, you should make yourself familiar with section 7.4.1 "Instance passivation and conversational state" of the EJB2.0 spec. -
3. Re: Stateless Session bean not thread safe?
lucluc May 4, 2002 3:31 AM (in response to lucluc)The stateful bean version works fine.
I'm reading Mastering EJB 2ed. by Ed Roman in which I found that ejbActivate and ejbPassivate don't apply to stateless session beans. It doesn't mind whatever action is taken by container on stateless bean already in pool, what matters is that the container should clear those stateless beans. So it doesn't matter if I'm trying to hold a state in a stateless bean, the container should clear it every time for me because stateless beans are thread safe.
Now, I don't want to hold a state in stateless bean 'cause it's quite insane, but for sake of testing I think it's seems not working very well.
ciao -
4. Re: Stateless Session bean not thread safe?
scoy May 4, 2002 5:22 AM (in response to lucluc)What makes you think that:
a) The container should "clear" stateless beans?
b) Stateless beans are "threadsafe"? -
5. Re: Stateless Session bean not thread safe?
lucluc May 4, 2002 5:57 AM (in response to lucluc)Sorry, I gave a bad problem's explanation.
Beans are single-threaded so they must be thread safe. I was meaning the effect that I noticed seemed a result of a not thread-safe operation.
Well, I think you're right because I've reread p.83 of Mastering EJB and I understood that I should expect my stateless bean to forget everything after each method call and NOT I should expect my container make the bean forget everything. That's a substantial difference!
I've also learned that I shouldn't rely on ejbCreate,ejbRemove method because this is a container's matter.
Thanks for time you spent.