users@glassfish.java.net

Singleton by limiting pool size to 1

From: <glassfish_at_javadesktop.org>
Date: Wed, 17 Feb 2010 07:12:24 PST

Hello,

One solution to implement Singleton pattern with EJB 3.0 is limit the pool size to 1. But I also like to ensure that the Singleton is the same instance across the cluster, I have used the following configuration in sun-ejb-jar.xml:

<ejb-name>SingletonSessionBean</ejb-name>
   <bean-pool>
            <steady-pool-size>1</steady-pool-size>
            <max-pool-size>1</max-pool-size>
           <pool-idle-timeout-in-seconds>0</pool-idle-timeout-in-seconds>
  </bean-pool>

The steady-pool-size parameter allows Glassfish to auto populate the pool was 1 instance of the session bean, but seems that when pool-idle-timeout-in-seconds is set to 0 (never times out) the steady-pool-size doesn't have any effect. I would like to know if there is anyone familiar with bean-pool configuration under Glassfish.

Also why it's not recommended if I can access shared data from a singleton POJO inside my EJB?

BR,
Mohamed
[Message sent by forum member 'mohamedelshami' (mohamed.shami_at_gmail.com)]

http://forums.java.net/jive/thread.jspa?messageID=387182