General J2EE: Calling a Singleton in Stateless Session EJB
- Posted by: Patil Srinivas
- Posted on: August 20 2005 07:10 EDT
I am doing a portal application and I am faced with the problem of passing objects between different portlets. Since each portlet sits in a different war file hence considering the default websphere configuration will running in different classloaders and will have different session objects. Initially I had defined a singleton hashtable and deployed it as a shared library on the Websphere Portal Server and everything was going fine. Later we realised that deploying and maintaining shared libraries on portal server is a pain, so we had come out with alternative solutions. One of my colleagues suggested, defining a stateless ejb and calling the singleton hashtable through stateless session ejb.Both the portlets will add and remove objects from the hashtable using the ejb. I have done a minimal implementaion of this and simple tests and it seems to work fine.
I was wondering if any of you have tried this and have any comments on this approach. Are there any worms lurking which I have not though about. Your feedback and suggestions will be greatfully appreciated.
Thanks and Regards,
After little bit further thinking, may the option described above is not viable. The reason being that not all ejb instances are guranteed to be loaded in the same JVM instance. As the spec says the ejb server may create and destroy JVM's as required, so this would lead to a situation where there may be multiple singletons. What is your opinion?
You did not mention which portal server you are currently using.
If you are using IBM Websphere Portal, you can use portlet services to share the objects across the portlets in Portal server.
For more information on using Portlet service look at IBM Portal Info center.
Here is a link to developerworks article on using portlet service..
Please post what portal server are you using?