Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Session bean and EJB container ?  RSS feed

 
AbdulRahman Mahmoud
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do the EJB container create only one instance for the session bean and use threading? or a new instance for each client when a client invoke the session bean?
 
Rob Spoor
Sheriff
Posts: 21090
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depends on the type of session bean.

For singleton session beans, there will be one instance in your application. This one instance may be accessed by several different threads. By default the container makes sure only one method may be accessed, but you can changed that using @Lock(LockType.READ) or @ConcurrencyManagement(ConcurrencyManagementType.BEAN).

For stateless session beans there are usually multiple instances. These may be reused (the container may pool some instances, and return instances from this pool), but each instance will be accessed by only one thread at a time.

Stateful session beans may be accessed from multiple threads at the same time, but the container must ensure that only one thread will have access at any given time. That means that if thread A calls method X of a stateful session bean, and thread B calls method Y of the same bean, then the container must make sure that the call to method X finishes for thread A before method Y will be called for thread B.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!