users@glassfish.java.net

Re: Bug? <max-pool-size> seems to count only idle EJB instances

From: Major Péter <majorpetya_at_sch.bme.hu>
Date: Mon, 30 Nov 2009 23:49:35 +0100

Hi,

create a static member field, which will contain your EJB object and
create initialization method (@PreConstruct), and initialize the field
if it's null, so basically you use the Singleton pattern to solve the issue.
Alternatively wait few days, until the Java EE 6 and GFv3 is out and use
@Singleton Session Beans with EJB3.1 . ;)

Regards,
Peter

2009-11-30 23:40 keltezéssel, glassfish_at_javadesktop.org írta:
> Hi
>
> I am trying to create an EJB which will always only have one actively executing instance, and which will have a steady-pool-size of zero, so that when idle there is absolutely no instances in the application server of my EJB.
>
> The reason is that I am interfacing to a command line driven program, and this program allows only one online instance to execute the commands I need to execute.
>
> My sun-ejb-jar.xml contains:
>
> <ejb-name>CnrConfigEJB</ejb-name>
> <bean-pool>
> <steady-pool-size>0</steady-pool-size>
> <resize-quantity>1</resize-quantity>
> <max-pool-size>1</max-pool-size>
> <pool-idle-timeout-in-seconds>30</pool-idle-timeout-in-seconds>
> </bean-pool>
>
> This works in a way in that an instance of the EJB is only created when there is actually a client calling the EJB, and after the client is done it lingers for 30 seconds waiting for more work, then it gets deleted (and the @Postdestruct method sends "quit" command to the command line application). Neat.
>
> However, if I have more than one client thread calling the EJB service, glassfish --- regardless of the value of <max-pool-size> keeps creating instances of the EJB, one for each executing client thread. Still, once the threads terminate, glassfish deletes the EJB instances again --- execept one instance, which is allowed to linger for 30 seconds.
>
> So it seems that glassfish <max-pool-size> only counts the number of idle EJB instances, not the number of executing EJB instances. Bug?
>
> How can I implement an EJB that only ever has one active instance running?
>
> Thanks for yout time,
> Jacob