dcsimg
EJB Singleton once again:)
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Ondrej_Galik
Posted On:   Wednesday, August 24, 2005 03:56 AM

Hi, I'm pretty new to EJB and I ran to a problem with singletons. I've read a lot about them, but most discussion didn't come to a satysfying conclusion. What I need is to create a singleton in my EJB application. This singleton should work as a repository for some large objects, which are immutable, does not contain any state and all the work they do can be managed using static methods. So there is no problem with synchronization, clustering etc. As I understood, it is not possible to implement a singleton as an EJB and setting its pool size to 1, because only one thread could perform tasks on the bean at a time. Is it possible to implement the class as a POJO, which will remain as a singleton in a memory? Thanks for any help    More>>

Hi, I'm pretty new to EJB and I ran to a problem with singletons. I've read a lot about them, but most discussion didn't come to a satysfying conclusion. What I need is to create a singleton in my EJB application. This singleton should work as a repository for some large objects, which are immutable, does not contain any state and all the work they do can be managed using static methods. So there is no problem with synchronization, clustering etc. As I understood, it is not possible to implement a singleton as an EJB and setting its pool size to 1, because only one thread could perform tasks on the bean at a time. Is it possible to implement the class as a POJO, which will remain as a singleton in a memory?
Thanks for any help

   <<Less

Re: EJB Singleton once again:)

Posted By:   Christopher_Koenigsberg  
Posted On:   Friday, August 26, 2005 10:12 AM

Is it possible to implement the class as a POJO, which will remain as a singleton in a memory?


You can of course write code for this, e.g. as a static field in a class with a private constructor and a static "getInstance()" factory method, and experiment to see if it works.



I don't really use EJB's so I'm not sure, but I think (?) you might run into problems with different ClassLoaders etc., where various EJB instances might not all see exactly the same copy of this "singleton" over time? e.g. some (but not all?) of them might get their own separately loaded version, of your "singleton" ....


I think you're perhaps better off putting this in a database instead?
About | Sitemap | Contact