-
1. Re: Are Stateless Session EJB Thread-safe
dimitris Dec 10, 2007 5:33 PM (in response to mjrother)Stateless session beans do no have identity so every concurrent request will actually be directed to a different instance from the stateless session bean pool. The server dynamically manages the pool size to deal with the request load.
-
2. Re: Are Stateless Session EJB Thread-safe
mjrother Dec 11, 2007 3:54 PM (in response to mjrother)Ok...What about the case where I have retrieved a handle to a single instance of a StatelessSessionEJB up front. Then multiple client threads try to invoke methods on the bean. Do they go to multiple EJB's as you suggest? If I look at the MBean for the EJB I only see 2 beans created.
-
3. Re: Are Stateless Session EJB Thread-safe
dimitris Dec 12, 2007 6:58 PM (in response to mjrother)I believe the multithreaded calls on the same handle will go to different bean instances.
-
4. Re: Are Stateless Session EJB Thread-safe
trunikov Dec 14, 2007 2:42 AM (in response to mjrother)I think that it depends on internal implementation of an application server. As I understand a SLSB should not has internal state. In this case, in theory, one instance of the SLSB enough to serve all client's call.
-
5. Re: Are Stateless Session EJB Thread-safe
dimitris Dec 14, 2007 3:16 AM (in response to mjrother)No. A bean is always guaranteed to be called by one thread at any given point.
-
6. Re: Are Stateless Session EJB Thread-safe
trunikov Dec 17, 2007 2:58 AM (in response to mjrother)"dimitris@jboss.org" wrote:
No. A bean is always guaranteed to be called by one thread at any given point.
May be I'm wrong about SLSB because I'm not strong with EJB, but I really don't see any sense in this guarantee. If code hasn't internal state it is thread safe, so any constraints are exceeded, isn't it? Could you explain the sense of this guarantee or point me where I may read about this constraint?
Thanks in advance,
Dmitry Trunikov -
7. Re: Are Stateless Session EJB Thread-safe
dimitris Dec 17, 2007 4:19 AM (in response to mjrother)What you miss is that SLSBs *can* have internal state, e.g. a cached datasource handle that they re-use to serve incoming requests.
Stateless is the interpretation from a client's point of view, so if a SLSB has 3 methods, a client should be able to call those methods on different bean instances, without that making any difference in the total outcome.
The single thread guarrantee of EJBs makes writing those beans easy, so you don't have to think about concurrency issues. It also scales well as the server will create as many SLBSs as they are needed to handle the load.
What you describe is a simple RMIServer singleton that must know how to deal with concurrent requests. That's a very different thing from EJBs. -
8. Re: Are Stateless Session EJB Thread-safe
khanna111 Dec 19, 2007 4:49 PM (in response to mjrother)If there are more than one threads from a single client, can they access the same SLSB simultaneously? If so, what exception would be thrown?
Thanks -
9. Re: Are Stateless Session EJB Thread-safe
dimitris Dec 19, 2007 5:02 PM (in response to mjrother)The best thing to do is to make a testcase and see what happens.
-
10. Re: Are Stateless Session EJB Thread-safe
yankeson Apr 13, 2014 2:56 AM (in response to mjrother)I think it's thread safe because one bean is created for a particular client, and this bean just holds the data of this particular client, that means the data are not shared by other clients.
-
11. Re: Are Stateless Session EJB Thread-safe
gregtk Apr 13, 2014 3:52 AM (in response to mjrother)Yes it's thread-safe. For more details you can check the "Pro EJB 3" book.
-
12. Re: Are Stateless Session EJB Thread-safe
wdfink Apr 13, 2014 4:38 AM (in response to yankeson)Yes, your answer is correct. But about 7 years too late
You should have a look to the last post date
-
13. Re: Are Stateless Session EJB Thread-safe
yankeson Apr 14, 2014 12:33 PM (in response to wdfink)Grigoriy and Wolf-Dieter, thank you both. I didn't notice the data when this post started. Anyway your answers confirm my understanding.