wood burning stoves 2.0*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes A bean cannot use both container and bean managed. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "A bean cannot use both container and bean managed." Watch "A bean cannot use both container and bean managed." New topic
Author

A bean cannot use both container and bean managed.

Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 763
On p.14 of Frit's notes

A singleton bean cannot use both container managed and bean managed concurrency.


I think any bean (singleton, stateless and stateful) cannot use both container managed and bean managed concurrency.
Reason:
A stateless or stateful bean are not shared by more than one client at a time, so I think they don't even need container/bean managed concurrency control at all. It won't make sense to use either or both managed concurrency control for a stateless or stateful bean.

Any comments?
Mike Degteariov
Ranch Hand

Joined: Oct 03, 2007
Posts: 61
    
    8

javax.ejb.ConcurrencyManagement annotation only works for singleton session beans.

It has no effect to other kinds of EJBs.

Here's where it is stated:
http://docs.oracle.com/javaee/6/api/javax/ejb/ConcurrencyManagement.html

It is said explicitly that "This annotation may be applied to stateful session beans, but doing so has no impact on the semantics of concurrency management for such beans."


Mike Degteariov
SCJP5 SCWCD5 SCBCD5
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 763
Thanks for your concurrency management documentation.
In EJB in Action, as I remember, it does not mention any concurrency for stateless bean. Does stateless bean need concurrency management?
Mike Degteariov
Ranch Hand

Joined: Oct 03, 2007
Posts: 61
    
    8

Stateless session bean only serve one client at a time.
This means that for the duration of the call this particular instance of stateless EJB will not be used to fulfil other requests.
Once the call to stateless EJB is completed, the bean returns to the pool and becames available for future calls.

If two different clients send two different requests to the same stateless session bean SIMULTANEOUSLY, most likely (an exception explained in next statement) they will be served by two different instances of this EJB taken (by the container) from the pool of available instances.
Note If the size of the pool is smaller that the number of simultaneous requests, there might be no new instance of stateless EJB available to fulfil the request, and so if it happens the container will most likely block the incoming request until an instance becomes available.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: A bean cannot use both container and bean managed.