Calling a Singleton in Stateless Session EJB

Discussions

General J2EE: Calling a Singleton in Stateless Session EJB

  1. Calling a Singleton in Stateless Session EJB (2 messages)

    Hi Guys/Gals

    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,
    Srinivas Patil
  2. 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?
  3. Hello,

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

    http://www-128.ibm.com/developerworks/websphere/library/techarticles/0406_kapaleeswaran/0406_kapaleeswaran.html

    Please post what portal server are you using?

    Cheers,

    Rajender Sriramoju