dev@glassfish.java.net

[gf-dev] Re: EJB pool

From: Mahesh Kannan <Mahesh.Kannan_at_Oracle.Com>
Date: Mon, 09 Feb 2015 12:16:34 -0800

On 02/09/2015 08:31 AM, Janario Oliveira wrote:
> Hi guys,
>
> I am trying to configure an ejb bean pool. But it is not working.
>
> I have one stateless (AsyncService) and I have added
> glassfish-ejb-jar.xml in WEB-INF
>
> glassfish-ejb-jar.xml:
> <sun-ejb-jar>
> <enterprise-beans>
> <ejb>
> <ejb-name>AsyncService</ejb-name>
> <bean-pool>
> <steady-pool-size>2</steady-pool-size>
> <resize-quantity>1</resize-quantity>
> <max-pool-size>5</max-pool-size>
> <pool-idle-timeout-in-seconds>300</pool-idle-timeout-in-seconds>
> </bean-pool>
> </ejb>
> </enterprise-beans>
> </sun-ejb-jar>
>
> It should limit AsyncService in maximum 5 instances. I've added a
> PostConstruct method to log creations.
>
> AsyncService:
> @Stateless
> public class AsyncService {
> @PostConstruct
> private void init() { System.out.println("Contruct AsyncService"); }
> @Asynchronous
> public Future<LocalDateTime> asyncTest() {...}
> }
>
>
> Calling the asyncTest in a loop of 15 times it creates more the
> maximum configured.

This is by design. We didn't want the incoming requests to be blocked
just because
      there are not enough stateless EJBs in the pool. So, when an
incoming request
      arrives and if there are no beans in the pool, the container will
create a new
      bean instance. However, the pool will hold only <max-pool-size>
beans. Bean
      instances that are created in excess of <max-pool-size> will be
destroyed when
      the request completes.

>
> Is there another way to configure that or are my configurations wrong?