i want to contrast ejb3 injection with the jndi lookup method, does injection bind 1 particular instance of proxy to the servlet ?? If so , then in a clustered environment such tight runtime binding could lead to inefficiencies .
Asked
Active
Viewed 483 times
0
1 Answers
2
For Stateless, an EJB proxy is 1-to-many with its backing instances (usually pooled) and is safe to inject into a servlet.
For Singleton, an EJB proxy is 1-to-1 with its backing instance, but the container (or bean) is responsible for ensuring the concurrent calls are either safe or disallowed, depending on business logic of each method. @AccessTimeout can be used to control how long to wait for a lock.
For Stateful, an EJB proxy is 1-to-1 with its backing instance and is not safe to inject into a servlet. As of EJB 3.1, stateful session bean concurrency allows some safety, but due to stateful session bean timeouts, injecting a stateful session bean into a servlet is unlikely to ever be useful.

Brett Kail
- 33,593
- 2
- 85
- 90
-
Good clean answer. Small addition, @AccessTimeout is a wonderful way to specify the "what if my bean is busy" conditions associated with multithreaded access. A definite friend to heavily concurrent systems and usable by all session beans. – David Blevins Jun 08 '11 at 03:51
-
Thanks :-). Updated the answer to note SFSB concurrency (though I still don't tink injecting an SFSB into a servlet is useful). – Brett Kail Jun 08 '11 at 23:15
-
Right, you'd probably want to look it up and keep it for a request or maybe stuff it into the session. Note @AccessTimeout on a Stateless bean specifies how long you may wait for an instance in the pool. On a Singleton it specifies how long you may wait for getting the lock. – David Blevins Jun 09 '11 at 00:01
-
Ah, I didn't realize @AccessTimeout had that effect for stateless. WebSphere Application Server, which I'm most familiar with, will always allocate an instance if necessary, and it will destroy the instance after the method completes if the pool is full. – Brett Kail Jun 09 '11 at 13:05
-
...though on a second reading of EJB 3.1 section 4.3.14, I don't see that @AccessTimeout applies to SLSB? – Brett Kail Jun 09 '11 at 13:10