• Post Reply Bookmark Topic Watch Topic
  • New Topic

Singleton In Ejb

 
Trish Wu
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to write a few session beans that resides on two different VM's and I am using WebSphere 3.5.4 and EJB1.0. I am faced with the problem of loading up a connection pool for middleware integradtion. Since I only want to load the pool up once per VM (under the condition of not allowing to write a servlet to do the job), is it possible to have a wrapper class that is GOF Singleton designed , which loads up the pool in its private constructor. So that the pool should only be loaded once per JVM.
Is this a bad practise??
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This should work, but you might run into classloader issues depending upon where you place the wrapper class.
Kyle
 
Trish Wu
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Kyle.
If I put that wrapper class as well as all the other beans stuff in a single ejb-jar file, it should be loaded with one classloader.
Quoted from: Wesbphere 3.5 system admin manual
JARClassLoader. There is one instance of it for each application server accessible through the EJBJARManager.
 
Michael Arndt
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
Without deeper knowledge of the Websphere product I would prefer the resource-reference solution. GOF Singleton in ejb envs sounds like a no no.
Where do you put your singleton class reference to keep it from being garbage collected if class-gc is enabled? When redeploying the application who guarantees closing connections held by your singleton (no guarantee to be finalized...).
Michael
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!