Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EJB3 and the Singleton

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi i am getting confused with Singleton EJB

As per the defination of Singleton EJB

A Singleton EJB is a session bean component that is instantiated once per application.
In other words, all requests to the singleton will be routed to the single instance of the Singleton bean instance.



( I know taht a Stateless session bean is not applicable here , as the container might maintain a pool of these stateless bean instances)

But Can you please tell me how this is different from a normal Stateful Session Bean ??



 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A singleton EJB ensures there is only one instance of an EJB in a application. There will be many instances of a stateful session bean (one per session) in a n application.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thank you that was useful .

Can you please tell me what will happen to the Singleton EJB , when concurrent (Simultanous) requests are made .

What i mean to ask is that do i need to use Synchronized keyword for the methods in it ??
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is up to how concurrency management is defined. If you are using container managed concurrency the container may lock on read or write access (or both). Its a general rule in EJBs (OK, one of mine ) that if you are thinking of using something that attempts to control threading behaviour such as the synchronized keyword you are probably doing somethign wrong.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay fine .

Now i really understanding how developers are lucky when going for EJB Container suppourt .

Thanks Paul .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic