File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes EJB3 and the Singleton Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB3 and the Singleton " Watch "EJB3 and the Singleton " New topic
Author

EJB3 and the Singleton

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234


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 ??




Save India From Corruption - Anna Hazare.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234


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

Joined: Apr 14, 2004
Posts: 10336

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

Joined: Apr 18, 2009
Posts: 2234

Okay fine .

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

Thanks Paul .
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: EJB3 and the Singleton
 
Similar Threads
Subclassing rules for Session beans
Doubt on DI
EJB 2.x Client view for EJB 3 bean
Servlet / Stateless Session Beam
Singleton class