You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Stuart Easterling <st...@gmail.com> on 2014/01/06 23:53:48 UTC

stateless bean pool -- all beans not available?

Hi, I am new to Tomee / OpenEJB.

I am trying to create a pool of 100 stateless local session beans. I have
the following in tomee.xml:

<Container id="foo" type="STATELESS">
    minSize = 100
    maxSize = 100
</Container>

In ejb-jar.xml:

<enterprise-beans>
    <session>
      <ejb-name>TestBean</ejb-name>
      <local-bean/>
      <ejb-class>com.foo.test.TestFooBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Bean</transaction-type>
    </session>
  </enterprise-beans>

It appears that all 100 beans are properly instantiated.

However, when I attempt to access them, only three bean instances are being
provided by the container, even when the invoking code must wait to gain
access to an instance.

I have looked through and searched the documentation but haven't been able
to resolve the problem. Any insights would be greatly appreciated !

Best,
Stuart

Re: stateless bean pool -- all beans not available?

Posted by Stuart Easterling <st...@gmail.com>.
Yes, within either your or my implementation, true, but I more meant that
the pooling behavior is divergent between your implementation and mine:
yours uses beans at random, mine uses the latest-instantiated, which is a
marked difference. I was just wondering if that difference in container
behavior looked familiar to you or others -- i.e. was explainable by an
obvious difference in configuration, or is related to your implementation
running from a custom main() method, and mine in the running server.
Best,
Stuart


On Tue, Jan 7, 2014 at 10:09 AM, Romain Manni-Bucau
<rm...@gmail.com>wrote:

> well from the implementaiton point of the view the difference is:
>
> if (async) {
>  thread.call(new Runnable() {
>  public voi run() { business();}
> } else {
>  business();
> }
>
> the pooling is the exact same one
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
>
>
>
> 2014/1/7 Stuart Easterling <st...@gmail.com>:
> > Hi Romain, I think I may need to do that (my current workaround is to
> use a
> > singleton bean and many threads, but I'd like to get my pool working too
> :
> > ). And also I greatly appreciate your providing that sample code, thank
> you.
> >
> > There is one other behavior which might shed some light on this: I just
> > tried my test code using asynchronous invocation of the business method
> (as
> > you do) and here's what's odd: my container always gives me the 100th
> > (last) bean instantiated -- which makes sense to me, since that bean is
> > available. Your container, though, seems to grab beans at random from the
> > pool.
> >
> > Does anything pop out to you that might explain this divergent behavior?
> > (This seems like two different implementations of the pooling
> behavior...?)
> >
> > Best,
> > Stuart
> >
> >
> > On Tue, Jan 7, 2014 at 9:35 AM, Romain Manni-Bucau <
> rmannibucau@gmail.com>wrote:
> >
> >> if called through the proxy (as an ejb clientà @Async does the same
> >> but in its own threads.
> >>
> >> Maybe start from my setup and add slowly elements until you hit your
> >> setup to find the issue?
> >> Romain Manni-Bucau
> >> Twitter: @rmannibucau
> >> Blog: http://rmannibucau.wordpress.com/
> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> >> Github: https://github.com/rmannibucau
> >>
> >>
> >>
> >> 2014/1/7 Stuart Easterling <st...@gmail.com>:
> >> > Hi Romain, many thanks for your reply.
> >> >
> >> > So I have a similar setup (assigning an integer value to each bean
> >> > instance, and sleeping the thread in the business method), although I
> am
> >> > looking up and invoking the beans from a commonj WorkManager which is
> >> kept
> >> > in the ServletContext, and my pool settings are set in tomee.xml. (As
> >> in, I
> >> > am running from within a web app, using Struts actually.)
> >> >
> >> > Also it does appear that my TestBean is assigned to the container
> 'foo'
> >> as
> >> > the number of bean instances increase and decrease when I adjust the
> >> > min/max size of the bean pool and restart the server. However the pool
> >> only
> >> > provides the last three beans that were instantiated for use by the
> >> client.
> >> >
> >> > One difference -- would this be significant? -- is my business method
> is
> >> > annotated as @Asynchronous.
> >> >
> >> > Best,
> >> > Stuart
> >> >
> >> >
> >> >
> >> > On Tue, Jan 7, 2014 at 5:01 AM, Romain Manni-Bucau <
> >> rmannibucau@gmail.com>wrote:
> >> >
> >> >> if you have this main:
> >> >>
> >> >> package org;
> >> >>
> >> >> import java.util.Properties;
> >> >> import java.util.concurrent.ExecutorService;
> >> >> import java.util.concurrent.Executors;
> >> >> import java.util.concurrent.TimeUnit;
> >> >> import javax.ejb.embeddable.EJBContainer;
> >> >> import javax.naming.Context;
> >> >> import javax.naming.NamingException;
> >> >>
> >> >> public class Main {
> >> >>     public static void main(String[] args) throws
> >> >> InterruptedException, NamingException {
> >> >>         final EJBContainer c = EJBContainer.createEJBContainer(new
> >> >> Properties() {{
> >> >>             setProperty("Default Stateless Container.MaxSize",
> "100");
> >> >>         }});
> >> >>         final Context ctx = c.getContext();
> >> >>         final TestBean bean =
> >> >> TestBean.class.cast(ctx.lookup("java:global/test/TestBean"));
> >> >>
> >> >>         final ExecutorService es = Executors.newFixedThreadPool(100);
> >> >>         for (int i = 0; i < 100; i++) {
> >> >>             es.submit(new Runnable() {
> >> >>                 @Override
> >> >>                 public void run() {
> >> >>                     bean.foo();
> >> >>                 }
> >> >>             });
> >> >>         }
> >> >>         es.shutdown();
> >> >>         es.awaitTermination(1, TimeUnit.DAYS);
> >> >>         c.close();
> >> >>     }
> >> >> }
> >> >>
> >> >>
> >> >> with this TestBean:
> >> >>
> >> >> package org;
> >> >>
> >> >> import java.util.concurrent.atomic.AtomicInteger;
> >> >> import javax.ejb.Stateless;
> >> >>
> >> >> @Stateless
> >> >> public class TestBean {
> >> >>     private static final AtomicInteger id = new AtomicInteger(1);
> >> >>
> >> >>     private int i = id.getAndIncrement();
> >> >>     private boolean done = false;
> >> >>
> >> >>     public void foo() {
> >> >>         if (!done) {
> >> >>             System.out.println(">>> " + i);
> >> >>         }
> >> >>         try {
> >> >>             Thread.sleep(200);
> >> >>         } catch (InterruptedException e) {
> >> >>             e.printStackTrace();
> >> >>         }
> >> >>     }
> >> >> }
> >> >>
> >> >> you get:
> >> >>
> >> >> >>> 27
> >> >> >>> 7
> >> >> >>> 35
> >> >> >>> 74
> >> >> >>> 34
> >> >> >>> 88
> >> >> >>> 64
> >> >> >>> 21
> >> >> >>> 63
> >> >> >>> 24
> >> >> >>> 99
> >> >> >>> 57
> >> >> >>> 78
> >> >> >>> 3
> >> >> >>> 36
> >> >> >>> 97
> >> >> >>> 20
> >> >> >>> 86
> >> >> >>> 92
> >> >> >>> 4
> >> >> >>> 96
> >> >> >>> 61
> >> >> >>> 49
> >> >> >>> 47
> >> >> >>> 93
> >> >> >>> 9
> >> >> >>> 22
> >> >> >>> 60
> >> >> >>> 29
> >> >> >>> 13
> >> >> >>> 46
> >> >> >>> 11
> >> >> >>> 66
> >> >> >>> 95
> >> >> >>> 1
> >> >> >>> 68
> >> >> >>> 45
> >> >> >>> 43
> >> >> >>> 54
> >> >> >>> 50
> >> >> >>> 33
> >> >> >>> 44
> >> >> >>> 85
> >> >> >>> 39
> >> >> >>> 79
> >> >> >>> 51
> >> >> >>> 31
> >> >> >>> 87
> >> >> >>> 25
> >> >> >>> 91
> >> >> >>> 42
> >> >> >>> 90
> >> >> >>> 84
> >> >> >>> 59
> >> >> >>> 10
> >> >> >>> 19
> >> >> >>> 62
> >> >> >>> 56
> >> >> >>> 53
> >> >> >>> 6
> >> >> >>> 5
> >> >> >>> 69
> >> >> >>> 83
> >> >> >>> 30
> >> >> >>> 41
> >> >> >>> 26
> >> >> >>> 71
> >> >> >>> 40
> >> >> >>> 67
> >> >> >>> 72
> >> >> >>> 75
> >> >> >>> 23
> >> >> >>> 48
> >> >> >>> 37
> >> >> >>> 38
> >> >> >>> 32
> >> >> >>> 14
> >> >> >>> 8
> >> >> >>> 16
> >> >> >>> 17
> >> >> >>> 12
> >> >> >>> 77
> >> >> >>> 82
> >> >> >>> 89
> >> >> >>> 76
> >> >> >>> 18
> >> >> >>> 70
> >> >> >>> 52
> >> >> >>> 2
> >> >> >>> 100
> >> >> >>> 58
> >> >> >>> 65
> >> >> >>> 94
> >> >> >>> 73
> >> >> >>> 80
> >> >> >>> 55
> >> >> >>> 28
> >> >> >>> 98
> >> >> >>> 15
> >> >> >>> 81
> >> >>
> >> >> Romain Manni-Bucau
> >> >> Twitter: @rmannibucau
> >> >> Blog: http://rmannibucau.wordpress.com/
> >> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> >> >> Github: https://github.com/rmannibucau
> >> >>
> >> >>
> >> >>
> >> >> 2014/1/7 Romain Manni-Bucau <rm...@gmail.com>:
> >> >> > Hi
> >> >> >
> >> >> > did you check in the log your container 'foo' is used for TestBean?
> >> >> > can you share a project showing this behavior?
> >> >> > Romain Manni-Bucau
> >> >> > Twitter: @rmannibucau
> >> >> > Blog: http://rmannibucau.wordpress.com/
> >> >> > LinkedIn: http://fr.linkedin.com/in/rmannibucau
> >> >> > Github: https://github.com/rmannibucau
> >> >> >
> >> >> >
> >> >> >
> >> >> > 2014/1/6 Stuart Easterling <st...@gmail.com>:
> >> >> >> Hi, I am new to Tomee / OpenEJB.
> >> >> >>
> >> >> >> I am trying to create a pool of 100 stateless local session
> beans. I
> >> >> have
> >> >> >> the following in tomee.xml:
> >> >> >>
> >> >> >> <Container id="foo" type="STATELESS">
> >> >> >>     minSize = 100
> >> >> >>     maxSize = 100
> >> >> >> </Container>
> >> >> >>
> >> >> >> In ejb-jar.xml:
> >> >> >>
> >> >> >> <enterprise-beans>
> >> >> >>     <session>
> >> >> >>       <ejb-name>TestBean</ejb-name>
> >> >> >>       <local-bean/>
> >> >> >>       <ejb-class>com.foo.test.TestFooBean</ejb-class>
> >> >> >>       <session-type>Stateless</session-type>
> >> >> >>       <transaction-type>Bean</transaction-type>
> >> >> >>     </session>
> >> >> >>   </enterprise-beans>
> >> >> >>
> >> >> >> It appears that all 100 beans are properly instantiated.
> >> >> >>
> >> >> >> However, when I attempt to access them, only three bean instances
> are
> >> >> being
> >> >> >> provided by the container, even when the invoking code must wait
> to
> >> gain
> >> >> >> access to an instance.
> >> >> >>
> >> >> >> I have looked through and searched the documentation but haven't
> been
> >> >> able
> >> >> >> to resolve the problem. Any insights would be greatly appreciated
> !
> >> >> >>
> >> >> >> Best,
> >> >> >> Stuart
> >> >>
> >>
>

Re: stateless bean pool -- all beans not available?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
well from the implementaiton point of the view the difference is:

if (async) {
 thread.call(new Runnable() {
 public voi run() { business();}
} else {
 business();
}

the pooling is the exact same one
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau



2014/1/7 Stuart Easterling <st...@gmail.com>:
> Hi Romain, I think I may need to do that (my current workaround is to use a
> singleton bean and many threads, but I'd like to get my pool working too :
> ). And also I greatly appreciate your providing that sample code, thank you.
>
> There is one other behavior which might shed some light on this: I just
> tried my test code using asynchronous invocation of the business method (as
> you do) and here's what's odd: my container always gives me the 100th
> (last) bean instantiated -- which makes sense to me, since that bean is
> available. Your container, though, seems to grab beans at random from the
> pool.
>
> Does anything pop out to you that might explain this divergent behavior?
> (This seems like two different implementations of the pooling behavior...?)
>
> Best,
> Stuart
>
>
> On Tue, Jan 7, 2014 at 9:35 AM, Romain Manni-Bucau <rm...@gmail.com>wrote:
>
>> if called through the proxy (as an ejb clientà @Async does the same
>> but in its own threads.
>>
>> Maybe start from my setup and add slowly elements until you hit your
>> setup to find the issue?
>> Romain Manni-Bucau
>> Twitter: @rmannibucau
>> Blog: http://rmannibucau.wordpress.com/
>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>> Github: https://github.com/rmannibucau
>>
>>
>>
>> 2014/1/7 Stuart Easterling <st...@gmail.com>:
>> > Hi Romain, many thanks for your reply.
>> >
>> > So I have a similar setup (assigning an integer value to each bean
>> > instance, and sleeping the thread in the business method), although I am
>> > looking up and invoking the beans from a commonj WorkManager which is
>> kept
>> > in the ServletContext, and my pool settings are set in tomee.xml. (As
>> in, I
>> > am running from within a web app, using Struts actually.)
>> >
>> > Also it does appear that my TestBean is assigned to the container 'foo'
>> as
>> > the number of bean instances increase and decrease when I adjust the
>> > min/max size of the bean pool and restart the server. However the pool
>> only
>> > provides the last three beans that were instantiated for use by the
>> client.
>> >
>> > One difference -- would this be significant? -- is my business method is
>> > annotated as @Asynchronous.
>> >
>> > Best,
>> > Stuart
>> >
>> >
>> >
>> > On Tue, Jan 7, 2014 at 5:01 AM, Romain Manni-Bucau <
>> rmannibucau@gmail.com>wrote:
>> >
>> >> if you have this main:
>> >>
>> >> package org;
>> >>
>> >> import java.util.Properties;
>> >> import java.util.concurrent.ExecutorService;
>> >> import java.util.concurrent.Executors;
>> >> import java.util.concurrent.TimeUnit;
>> >> import javax.ejb.embeddable.EJBContainer;
>> >> import javax.naming.Context;
>> >> import javax.naming.NamingException;
>> >>
>> >> public class Main {
>> >>     public static void main(String[] args) throws
>> >> InterruptedException, NamingException {
>> >>         final EJBContainer c = EJBContainer.createEJBContainer(new
>> >> Properties() {{
>> >>             setProperty("Default Stateless Container.MaxSize", "100");
>> >>         }});
>> >>         final Context ctx = c.getContext();
>> >>         final TestBean bean =
>> >> TestBean.class.cast(ctx.lookup("java:global/test/TestBean"));
>> >>
>> >>         final ExecutorService es = Executors.newFixedThreadPool(100);
>> >>         for (int i = 0; i < 100; i++) {
>> >>             es.submit(new Runnable() {
>> >>                 @Override
>> >>                 public void run() {
>> >>                     bean.foo();
>> >>                 }
>> >>             });
>> >>         }
>> >>         es.shutdown();
>> >>         es.awaitTermination(1, TimeUnit.DAYS);
>> >>         c.close();
>> >>     }
>> >> }
>> >>
>> >>
>> >> with this TestBean:
>> >>
>> >> package org;
>> >>
>> >> import java.util.concurrent.atomic.AtomicInteger;
>> >> import javax.ejb.Stateless;
>> >>
>> >> @Stateless
>> >> public class TestBean {
>> >>     private static final AtomicInteger id = new AtomicInteger(1);
>> >>
>> >>     private int i = id.getAndIncrement();
>> >>     private boolean done = false;
>> >>
>> >>     public void foo() {
>> >>         if (!done) {
>> >>             System.out.println(">>> " + i);
>> >>         }
>> >>         try {
>> >>             Thread.sleep(200);
>> >>         } catch (InterruptedException e) {
>> >>             e.printStackTrace();
>> >>         }
>> >>     }
>> >> }
>> >>
>> >> you get:
>> >>
>> >> >>> 27
>> >> >>> 7
>> >> >>> 35
>> >> >>> 74
>> >> >>> 34
>> >> >>> 88
>> >> >>> 64
>> >> >>> 21
>> >> >>> 63
>> >> >>> 24
>> >> >>> 99
>> >> >>> 57
>> >> >>> 78
>> >> >>> 3
>> >> >>> 36
>> >> >>> 97
>> >> >>> 20
>> >> >>> 86
>> >> >>> 92
>> >> >>> 4
>> >> >>> 96
>> >> >>> 61
>> >> >>> 49
>> >> >>> 47
>> >> >>> 93
>> >> >>> 9
>> >> >>> 22
>> >> >>> 60
>> >> >>> 29
>> >> >>> 13
>> >> >>> 46
>> >> >>> 11
>> >> >>> 66
>> >> >>> 95
>> >> >>> 1
>> >> >>> 68
>> >> >>> 45
>> >> >>> 43
>> >> >>> 54
>> >> >>> 50
>> >> >>> 33
>> >> >>> 44
>> >> >>> 85
>> >> >>> 39
>> >> >>> 79
>> >> >>> 51
>> >> >>> 31
>> >> >>> 87
>> >> >>> 25
>> >> >>> 91
>> >> >>> 42
>> >> >>> 90
>> >> >>> 84
>> >> >>> 59
>> >> >>> 10
>> >> >>> 19
>> >> >>> 62
>> >> >>> 56
>> >> >>> 53
>> >> >>> 6
>> >> >>> 5
>> >> >>> 69
>> >> >>> 83
>> >> >>> 30
>> >> >>> 41
>> >> >>> 26
>> >> >>> 71
>> >> >>> 40
>> >> >>> 67
>> >> >>> 72
>> >> >>> 75
>> >> >>> 23
>> >> >>> 48
>> >> >>> 37
>> >> >>> 38
>> >> >>> 32
>> >> >>> 14
>> >> >>> 8
>> >> >>> 16
>> >> >>> 17
>> >> >>> 12
>> >> >>> 77
>> >> >>> 82
>> >> >>> 89
>> >> >>> 76
>> >> >>> 18
>> >> >>> 70
>> >> >>> 52
>> >> >>> 2
>> >> >>> 100
>> >> >>> 58
>> >> >>> 65
>> >> >>> 94
>> >> >>> 73
>> >> >>> 80
>> >> >>> 55
>> >> >>> 28
>> >> >>> 98
>> >> >>> 15
>> >> >>> 81
>> >>
>> >> Romain Manni-Bucau
>> >> Twitter: @rmannibucau
>> >> Blog: http://rmannibucau.wordpress.com/
>> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>> >> Github: https://github.com/rmannibucau
>> >>
>> >>
>> >>
>> >> 2014/1/7 Romain Manni-Bucau <rm...@gmail.com>:
>> >> > Hi
>> >> >
>> >> > did you check in the log your container 'foo' is used for TestBean?
>> >> > can you share a project showing this behavior?
>> >> > Romain Manni-Bucau
>> >> > Twitter: @rmannibucau
>> >> > Blog: http://rmannibucau.wordpress.com/
>> >> > LinkedIn: http://fr.linkedin.com/in/rmannibucau
>> >> > Github: https://github.com/rmannibucau
>> >> >
>> >> >
>> >> >
>> >> > 2014/1/6 Stuart Easterling <st...@gmail.com>:
>> >> >> Hi, I am new to Tomee / OpenEJB.
>> >> >>
>> >> >> I am trying to create a pool of 100 stateless local session beans. I
>> >> have
>> >> >> the following in tomee.xml:
>> >> >>
>> >> >> <Container id="foo" type="STATELESS">
>> >> >>     minSize = 100
>> >> >>     maxSize = 100
>> >> >> </Container>
>> >> >>
>> >> >> In ejb-jar.xml:
>> >> >>
>> >> >> <enterprise-beans>
>> >> >>     <session>
>> >> >>       <ejb-name>TestBean</ejb-name>
>> >> >>       <local-bean/>
>> >> >>       <ejb-class>com.foo.test.TestFooBean</ejb-class>
>> >> >>       <session-type>Stateless</session-type>
>> >> >>       <transaction-type>Bean</transaction-type>
>> >> >>     </session>
>> >> >>   </enterprise-beans>
>> >> >>
>> >> >> It appears that all 100 beans are properly instantiated.
>> >> >>
>> >> >> However, when I attempt to access them, only three bean instances are
>> >> being
>> >> >> provided by the container, even when the invoking code must wait to
>> gain
>> >> >> access to an instance.
>> >> >>
>> >> >> I have looked through and searched the documentation but haven't been
>> >> able
>> >> >> to resolve the problem. Any insights would be greatly appreciated !
>> >> >>
>> >> >> Best,
>> >> >> Stuart
>> >>
>>

Re: stateless bean pool -- all beans not available?

Posted by Stuart Easterling <st...@gmail.com>.
I should also determine if the implementation of commonsj.WorkManager that
I am using (commonj.myfoo.de) is -- for some reason -- the problem. Will
update soon.
Best,
Stuart


On Tue, Jan 7, 2014 at 11:38 AM, Stuart Easterling <
stuart.easterling@gmail.com> wrote:

> Update: I have successfully run Romain's code and it performs as
> advertised.
>
> However, when I deploy Romain's bean to the Tomee server, the pool has the
> same problems as before: only one bean is provided to the client by the
> container.
>
> As in the output looks like:
>
> >>> 35
> >>> 35
> >>> 35
>
> .. and so on.
>
> Log output in the constructor indicates 100 beans are instantiated. The
> tomee log output says:
>
> INFO: Created Ejb(deployment-id=foo, ejb-name=TestBean, container=foo)
>
> and
>
> INFO: Started Ejb(deployment-id=foo, ejb-name=TestBean, container=foo)
>
> My deployment info is as follows:
>
> In tomee.xml I have only:
>
>
> <Container id="foo" type="STATELESS">
>     minSize = 100
>     maxSize = 100
> </Container>
>
> In ejb-jar.xml:
>
>  <session>
>       <ejb-name>TestBean</ejb-name>
>       <ejb-class>org.TestBean</ejb-class>
>       <session-type>Stateless</session-type>
>       <transaction-type>Container</transaction-type>
>     </session>
>
>
> Best,
> Stuart
>
>
> On Tue, Jan 7, 2014 at 11:01 AM, Stuart Easterling <
> stuart.easterling@gmail.com> wrote:
>
>> Hi Howard, thanks for your reply. To clarify, the singleton bean is not
>> the issue: that is working fine, and as expected there is only one bean
>> instantiated. I only mentioned this to clarify that I do have a workaround
>> for now. : )
>>
>> The problem I am having is with the stateless session bean pool. For a
>> pool of 100 instances, the container is only making the last 3 instantiated
>> beans available to me (for details see my previous post).
>>
>> In addition, the differences between the behavior of my test
>> implementation and Romain's is odd: it seems the two containers are
>> behaving quite differently as far as bean pooling, and I am wondering if
>> this might help explain the problem with my container/pool.
>>
>> Best,
>> Stuart
>>
>>
>> On Tue, Jan 7, 2014 at 10:46 AM, Howard W. Smith, Jr. <
>> smithh032772@gmail.com> wrote:
>>
>>> Stuart,
>>>
>>> On Tue, Jan 7, 2014 at 10:03 AM, Stuart Easterling <
>>> stuart.easterling@gmail.com> wrote:
>>>
>>> > Hi Romain, I think I may need to do that (my current workaround is to
>>> use a
>>> > singleton bean and many threads, but I'd like to get my pool working
>>> too :
>>> > ).
>>> >
>>>
>>> you seem to want to know the difference between the behavior/execution of
>>> your code and Romain's code. you mentioned 'singleton bean and many
>>> threads', above. did you share your singleton bean code already in this
>>> thread? sorry if i missed that.
>>>
>>> i'm asking/responding, as you asked if anyone seen this behavior before
>>> (in
>>> their app). the only time, I've seen similar behavior is with my
>>> singleton
>>> beans... the latest (or only) instantiated singleton bean...is
>>> used/referenced.
>>>
>>
>>
>

Re: stateless bean pool -- all beans not available?

Posted by Stuart Easterling <st...@gmail.com>.
Update: I have successfully run Romain's code and it performs as advertised.

However, when I deploy Romain's bean to the Tomee server, the pool has the
same problems as before: only one bean is provided to the client by the
container.

As in the output looks like:

>>> 35
>>> 35
>>> 35

.. and so on.

Log output in the constructor indicates 100 beans are instantiated. The
tomee log output says:

INFO: Created Ejb(deployment-id=foo, ejb-name=TestBean, container=foo)

and

INFO: Started Ejb(deployment-id=foo, ejb-name=TestBean, container=foo)

My deployment info is as follows:

In tomee.xml I have only:

<Container id="foo" type="STATELESS">
    minSize = 100
    maxSize = 100
</Container>

In ejb-jar.xml:

 <session>
      <ejb-name>TestBean</ejb-name>
      <ejb-class>org.TestBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>
    </session>


Best,
Stuart


On Tue, Jan 7, 2014 at 11:01 AM, Stuart Easterling <
stuart.easterling@gmail.com> wrote:

> Hi Howard, thanks for your reply. To clarify, the singleton bean is not
> the issue: that is working fine, and as expected there is only one bean
> instantiated. I only mentioned this to clarify that I do have a workaround
> for now. : )
>
> The problem I am having is with the stateless session bean pool. For a
> pool of 100 instances, the container is only making the last 3 instantiated
> beans available to me (for details see my previous post).
>
> In addition, the differences between the behavior of my test
> implementation and Romain's is odd: it seems the two containers are
> behaving quite differently as far as bean pooling, and I am wondering if
> this might help explain the problem with my container/pool.
>
> Best,
> Stuart
>
>
> On Tue, Jan 7, 2014 at 10:46 AM, Howard W. Smith, Jr. <
> smithh032772@gmail.com> wrote:
>
>> Stuart,
>>
>> On Tue, Jan 7, 2014 at 10:03 AM, Stuart Easterling <
>> stuart.easterling@gmail.com> wrote:
>>
>> > Hi Romain, I think I may need to do that (my current workaround is to
>> use a
>> > singleton bean and many threads, but I'd like to get my pool working
>> too :
>> > ).
>> >
>>
>> you seem to want to know the difference between the behavior/execution of
>> your code and Romain's code. you mentioned 'singleton bean and many
>> threads', above. did you share your singleton bean code already in this
>> thread? sorry if i missed that.
>>
>> i'm asking/responding, as you asked if anyone seen this behavior before
>> (in
>> their app). the only time, I've seen similar behavior is with my singleton
>> beans... the latest (or only) instantiated singleton bean...is
>> used/referenced.
>>
>
>

Re: stateless bean pool -- all beans not available?

Posted by Stuart Easterling <st...@gmail.com>.
Hi Howard, thanks for your reply. To clarify, the singleton bean is not the
issue: that is working fine, and as expected there is only one bean
instantiated. I only mentioned this to clarify that I do have a workaround
for now. : )

The problem I am having is with the stateless session bean pool. For a pool
of 100 instances, the container is only making the last 3 instantiated
beans available to me (for details see my previous post).

In addition, the differences between the behavior of my test implementation
and Romain's is odd: it seems the two containers are behaving quite
differently as far as bean pooling, and I am wondering if this might help
explain the problem with my container/pool.

Best,
Stuart


On Tue, Jan 7, 2014 at 10:46 AM, Howard W. Smith, Jr. <
smithh032772@gmail.com> wrote:

> Stuart,
>
> On Tue, Jan 7, 2014 at 10:03 AM, Stuart Easterling <
> stuart.easterling@gmail.com> wrote:
>
> > Hi Romain, I think I may need to do that (my current workaround is to
> use a
> > singleton bean and many threads, but I'd like to get my pool working too
> :
> > ).
> >
>
> you seem to want to know the difference between the behavior/execution of
> your code and Romain's code. you mentioned 'singleton bean and many
> threads', above. did you share your singleton bean code already in this
> thread? sorry if i missed that.
>
> i'm asking/responding, as you asked if anyone seen this behavior before (in
> their app). the only time, I've seen similar behavior is with my singleton
> beans... the latest (or only) instantiated singleton bean...is
> used/referenced.
>

Re: stateless bean pool -- all beans not available?

Posted by "Howard W. Smith, Jr." <sm...@gmail.com>.
Stuart,

On Tue, Jan 7, 2014 at 10:03 AM, Stuart Easterling <
stuart.easterling@gmail.com> wrote:

> Hi Romain, I think I may need to do that (my current workaround is to use a
> singleton bean and many threads, but I'd like to get my pool working too :
> ).
>

you seem to want to know the difference between the behavior/execution of
your code and Romain's code. you mentioned 'singleton bean and many
threads', above. did you share your singleton bean code already in this
thread? sorry if i missed that.

i'm asking/responding, as you asked if anyone seen this behavior before (in
their app). the only time, I've seen similar behavior is with my singleton
beans... the latest (or only) instantiated singleton bean...is
used/referenced.

Re: stateless bean pool -- all beans not available?

Posted by Stuart Easterling <st...@gmail.com>.
Hi Romain, I think I may need to do that (my current workaround is to use a
singleton bean and many threads, but I'd like to get my pool working too :
). And also I greatly appreciate your providing that sample code, thank you.

There is one other behavior which might shed some light on this: I just
tried my test code using asynchronous invocation of the business method (as
you do) and here's what's odd: my container always gives me the 100th
(last) bean instantiated -- which makes sense to me, since that bean is
available. Your container, though, seems to grab beans at random from the
pool.

Does anything pop out to you that might explain this divergent behavior?
(This seems like two different implementations of the pooling behavior...?)

Best,
Stuart


On Tue, Jan 7, 2014 at 9:35 AM, Romain Manni-Bucau <rm...@gmail.com>wrote:

> if called through the proxy (as an ejb clientà @Async does the same
> but in its own threads.
>
> Maybe start from my setup and add slowly elements until you hit your
> setup to find the issue?
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
>
>
>
> 2014/1/7 Stuart Easterling <st...@gmail.com>:
> > Hi Romain, many thanks for your reply.
> >
> > So I have a similar setup (assigning an integer value to each bean
> > instance, and sleeping the thread in the business method), although I am
> > looking up and invoking the beans from a commonj WorkManager which is
> kept
> > in the ServletContext, and my pool settings are set in tomee.xml. (As
> in, I
> > am running from within a web app, using Struts actually.)
> >
> > Also it does appear that my TestBean is assigned to the container 'foo'
> as
> > the number of bean instances increase and decrease when I adjust the
> > min/max size of the bean pool and restart the server. However the pool
> only
> > provides the last three beans that were instantiated for use by the
> client.
> >
> > One difference -- would this be significant? -- is my business method is
> > annotated as @Asynchronous.
> >
> > Best,
> > Stuart
> >
> >
> >
> > On Tue, Jan 7, 2014 at 5:01 AM, Romain Manni-Bucau <
> rmannibucau@gmail.com>wrote:
> >
> >> if you have this main:
> >>
> >> package org;
> >>
> >> import java.util.Properties;
> >> import java.util.concurrent.ExecutorService;
> >> import java.util.concurrent.Executors;
> >> import java.util.concurrent.TimeUnit;
> >> import javax.ejb.embeddable.EJBContainer;
> >> import javax.naming.Context;
> >> import javax.naming.NamingException;
> >>
> >> public class Main {
> >>     public static void main(String[] args) throws
> >> InterruptedException, NamingException {
> >>         final EJBContainer c = EJBContainer.createEJBContainer(new
> >> Properties() {{
> >>             setProperty("Default Stateless Container.MaxSize", "100");
> >>         }});
> >>         final Context ctx = c.getContext();
> >>         final TestBean bean =
> >> TestBean.class.cast(ctx.lookup("java:global/test/TestBean"));
> >>
> >>         final ExecutorService es = Executors.newFixedThreadPool(100);
> >>         for (int i = 0; i < 100; i++) {
> >>             es.submit(new Runnable() {
> >>                 @Override
> >>                 public void run() {
> >>                     bean.foo();
> >>                 }
> >>             });
> >>         }
> >>         es.shutdown();
> >>         es.awaitTermination(1, TimeUnit.DAYS);
> >>         c.close();
> >>     }
> >> }
> >>
> >>
> >> with this TestBean:
> >>
> >> package org;
> >>
> >> import java.util.concurrent.atomic.AtomicInteger;
> >> import javax.ejb.Stateless;
> >>
> >> @Stateless
> >> public class TestBean {
> >>     private static final AtomicInteger id = new AtomicInteger(1);
> >>
> >>     private int i = id.getAndIncrement();
> >>     private boolean done = false;
> >>
> >>     public void foo() {
> >>         if (!done) {
> >>             System.out.println(">>> " + i);
> >>         }
> >>         try {
> >>             Thread.sleep(200);
> >>         } catch (InterruptedException e) {
> >>             e.printStackTrace();
> >>         }
> >>     }
> >> }
> >>
> >> you get:
> >>
> >> >>> 27
> >> >>> 7
> >> >>> 35
> >> >>> 74
> >> >>> 34
> >> >>> 88
> >> >>> 64
> >> >>> 21
> >> >>> 63
> >> >>> 24
> >> >>> 99
> >> >>> 57
> >> >>> 78
> >> >>> 3
> >> >>> 36
> >> >>> 97
> >> >>> 20
> >> >>> 86
> >> >>> 92
> >> >>> 4
> >> >>> 96
> >> >>> 61
> >> >>> 49
> >> >>> 47
> >> >>> 93
> >> >>> 9
> >> >>> 22
> >> >>> 60
> >> >>> 29
> >> >>> 13
> >> >>> 46
> >> >>> 11
> >> >>> 66
> >> >>> 95
> >> >>> 1
> >> >>> 68
> >> >>> 45
> >> >>> 43
> >> >>> 54
> >> >>> 50
> >> >>> 33
> >> >>> 44
> >> >>> 85
> >> >>> 39
> >> >>> 79
> >> >>> 51
> >> >>> 31
> >> >>> 87
> >> >>> 25
> >> >>> 91
> >> >>> 42
> >> >>> 90
> >> >>> 84
> >> >>> 59
> >> >>> 10
> >> >>> 19
> >> >>> 62
> >> >>> 56
> >> >>> 53
> >> >>> 6
> >> >>> 5
> >> >>> 69
> >> >>> 83
> >> >>> 30
> >> >>> 41
> >> >>> 26
> >> >>> 71
> >> >>> 40
> >> >>> 67
> >> >>> 72
> >> >>> 75
> >> >>> 23
> >> >>> 48
> >> >>> 37
> >> >>> 38
> >> >>> 32
> >> >>> 14
> >> >>> 8
> >> >>> 16
> >> >>> 17
> >> >>> 12
> >> >>> 77
> >> >>> 82
> >> >>> 89
> >> >>> 76
> >> >>> 18
> >> >>> 70
> >> >>> 52
> >> >>> 2
> >> >>> 100
> >> >>> 58
> >> >>> 65
> >> >>> 94
> >> >>> 73
> >> >>> 80
> >> >>> 55
> >> >>> 28
> >> >>> 98
> >> >>> 15
> >> >>> 81
> >>
> >> Romain Manni-Bucau
> >> Twitter: @rmannibucau
> >> Blog: http://rmannibucau.wordpress.com/
> >> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> >> Github: https://github.com/rmannibucau
> >>
> >>
> >>
> >> 2014/1/7 Romain Manni-Bucau <rm...@gmail.com>:
> >> > Hi
> >> >
> >> > did you check in the log your container 'foo' is used for TestBean?
> >> > can you share a project showing this behavior?
> >> > Romain Manni-Bucau
> >> > Twitter: @rmannibucau
> >> > Blog: http://rmannibucau.wordpress.com/
> >> > LinkedIn: http://fr.linkedin.com/in/rmannibucau
> >> > Github: https://github.com/rmannibucau
> >> >
> >> >
> >> >
> >> > 2014/1/6 Stuart Easterling <st...@gmail.com>:
> >> >> Hi, I am new to Tomee / OpenEJB.
> >> >>
> >> >> I am trying to create a pool of 100 stateless local session beans. I
> >> have
> >> >> the following in tomee.xml:
> >> >>
> >> >> <Container id="foo" type="STATELESS">
> >> >>     minSize = 100
> >> >>     maxSize = 100
> >> >> </Container>
> >> >>
> >> >> In ejb-jar.xml:
> >> >>
> >> >> <enterprise-beans>
> >> >>     <session>
> >> >>       <ejb-name>TestBean</ejb-name>
> >> >>       <local-bean/>
> >> >>       <ejb-class>com.foo.test.TestFooBean</ejb-class>
> >> >>       <session-type>Stateless</session-type>
> >> >>       <transaction-type>Bean</transaction-type>
> >> >>     </session>
> >> >>   </enterprise-beans>
> >> >>
> >> >> It appears that all 100 beans are properly instantiated.
> >> >>
> >> >> However, when I attempt to access them, only three bean instances are
> >> being
> >> >> provided by the container, even when the invoking code must wait to
> gain
> >> >> access to an instance.
> >> >>
> >> >> I have looked through and searched the documentation but haven't been
> >> able
> >> >> to resolve the problem. Any insights would be greatly appreciated !
> >> >>
> >> >> Best,
> >> >> Stuart
> >>
>

Re: stateless bean pool -- all beans not available?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
if called through the proxy (as an ejb clientà @Async does the same
but in its own threads.

Maybe start from my setup and add slowly elements until you hit your
setup to find the issue?
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau



2014/1/7 Stuart Easterling <st...@gmail.com>:
> Hi Romain, many thanks for your reply.
>
> So I have a similar setup (assigning an integer value to each bean
> instance, and sleeping the thread in the business method), although I am
> looking up and invoking the beans from a commonj WorkManager which is kept
> in the ServletContext, and my pool settings are set in tomee.xml. (As in, I
> am running from within a web app, using Struts actually.)
>
> Also it does appear that my TestBean is assigned to the container 'foo' as
> the number of bean instances increase and decrease when I adjust the
> min/max size of the bean pool and restart the server. However the pool only
> provides the last three beans that were instantiated for use by the client.
>
> One difference -- would this be significant? -- is my business method is
> annotated as @Asynchronous.
>
> Best,
> Stuart
>
>
>
> On Tue, Jan 7, 2014 at 5:01 AM, Romain Manni-Bucau <rm...@gmail.com>wrote:
>
>> if you have this main:
>>
>> package org;
>>
>> import java.util.Properties;
>> import java.util.concurrent.ExecutorService;
>> import java.util.concurrent.Executors;
>> import java.util.concurrent.TimeUnit;
>> import javax.ejb.embeddable.EJBContainer;
>> import javax.naming.Context;
>> import javax.naming.NamingException;
>>
>> public class Main {
>>     public static void main(String[] args) throws
>> InterruptedException, NamingException {
>>         final EJBContainer c = EJBContainer.createEJBContainer(new
>> Properties() {{
>>             setProperty("Default Stateless Container.MaxSize", "100");
>>         }});
>>         final Context ctx = c.getContext();
>>         final TestBean bean =
>> TestBean.class.cast(ctx.lookup("java:global/test/TestBean"));
>>
>>         final ExecutorService es = Executors.newFixedThreadPool(100);
>>         for (int i = 0; i < 100; i++) {
>>             es.submit(new Runnable() {
>>                 @Override
>>                 public void run() {
>>                     bean.foo();
>>                 }
>>             });
>>         }
>>         es.shutdown();
>>         es.awaitTermination(1, TimeUnit.DAYS);
>>         c.close();
>>     }
>> }
>>
>>
>> with this TestBean:
>>
>> package org;
>>
>> import java.util.concurrent.atomic.AtomicInteger;
>> import javax.ejb.Stateless;
>>
>> @Stateless
>> public class TestBean {
>>     private static final AtomicInteger id = new AtomicInteger(1);
>>
>>     private int i = id.getAndIncrement();
>>     private boolean done = false;
>>
>>     public void foo() {
>>         if (!done) {
>>             System.out.println(">>> " + i);
>>         }
>>         try {
>>             Thread.sleep(200);
>>         } catch (InterruptedException e) {
>>             e.printStackTrace();
>>         }
>>     }
>> }
>>
>> you get:
>>
>> >>> 27
>> >>> 7
>> >>> 35
>> >>> 74
>> >>> 34
>> >>> 88
>> >>> 64
>> >>> 21
>> >>> 63
>> >>> 24
>> >>> 99
>> >>> 57
>> >>> 78
>> >>> 3
>> >>> 36
>> >>> 97
>> >>> 20
>> >>> 86
>> >>> 92
>> >>> 4
>> >>> 96
>> >>> 61
>> >>> 49
>> >>> 47
>> >>> 93
>> >>> 9
>> >>> 22
>> >>> 60
>> >>> 29
>> >>> 13
>> >>> 46
>> >>> 11
>> >>> 66
>> >>> 95
>> >>> 1
>> >>> 68
>> >>> 45
>> >>> 43
>> >>> 54
>> >>> 50
>> >>> 33
>> >>> 44
>> >>> 85
>> >>> 39
>> >>> 79
>> >>> 51
>> >>> 31
>> >>> 87
>> >>> 25
>> >>> 91
>> >>> 42
>> >>> 90
>> >>> 84
>> >>> 59
>> >>> 10
>> >>> 19
>> >>> 62
>> >>> 56
>> >>> 53
>> >>> 6
>> >>> 5
>> >>> 69
>> >>> 83
>> >>> 30
>> >>> 41
>> >>> 26
>> >>> 71
>> >>> 40
>> >>> 67
>> >>> 72
>> >>> 75
>> >>> 23
>> >>> 48
>> >>> 37
>> >>> 38
>> >>> 32
>> >>> 14
>> >>> 8
>> >>> 16
>> >>> 17
>> >>> 12
>> >>> 77
>> >>> 82
>> >>> 89
>> >>> 76
>> >>> 18
>> >>> 70
>> >>> 52
>> >>> 2
>> >>> 100
>> >>> 58
>> >>> 65
>> >>> 94
>> >>> 73
>> >>> 80
>> >>> 55
>> >>> 28
>> >>> 98
>> >>> 15
>> >>> 81
>>
>> Romain Manni-Bucau
>> Twitter: @rmannibucau
>> Blog: http://rmannibucau.wordpress.com/
>> LinkedIn: http://fr.linkedin.com/in/rmannibucau
>> Github: https://github.com/rmannibucau
>>
>>
>>
>> 2014/1/7 Romain Manni-Bucau <rm...@gmail.com>:
>> > Hi
>> >
>> > did you check in the log your container 'foo' is used for TestBean?
>> > can you share a project showing this behavior?
>> > Romain Manni-Bucau
>> > Twitter: @rmannibucau
>> > Blog: http://rmannibucau.wordpress.com/
>> > LinkedIn: http://fr.linkedin.com/in/rmannibucau
>> > Github: https://github.com/rmannibucau
>> >
>> >
>> >
>> > 2014/1/6 Stuart Easterling <st...@gmail.com>:
>> >> Hi, I am new to Tomee / OpenEJB.
>> >>
>> >> I am trying to create a pool of 100 stateless local session beans. I
>> have
>> >> the following in tomee.xml:
>> >>
>> >> <Container id="foo" type="STATELESS">
>> >>     minSize = 100
>> >>     maxSize = 100
>> >> </Container>
>> >>
>> >> In ejb-jar.xml:
>> >>
>> >> <enterprise-beans>
>> >>     <session>
>> >>       <ejb-name>TestBean</ejb-name>
>> >>       <local-bean/>
>> >>       <ejb-class>com.foo.test.TestFooBean</ejb-class>
>> >>       <session-type>Stateless</session-type>
>> >>       <transaction-type>Bean</transaction-type>
>> >>     </session>
>> >>   </enterprise-beans>
>> >>
>> >> It appears that all 100 beans are properly instantiated.
>> >>
>> >> However, when I attempt to access them, only three bean instances are
>> being
>> >> provided by the container, even when the invoking code must wait to gain
>> >> access to an instance.
>> >>
>> >> I have looked through and searched the documentation but haven't been
>> able
>> >> to resolve the problem. Any insights would be greatly appreciated !
>> >>
>> >> Best,
>> >> Stuart
>>

Re: stateless bean pool -- all beans not available?

Posted by Stuart Easterling <st...@gmail.com>.
Hi Romain, many thanks for your reply.

So I have a similar setup (assigning an integer value to each bean
instance, and sleeping the thread in the business method), although I am
looking up and invoking the beans from a commonj WorkManager which is kept
in the ServletContext, and my pool settings are set in tomee.xml. (As in, I
am running from within a web app, using Struts actually.)

Also it does appear that my TestBean is assigned to the container 'foo' as
the number of bean instances increase and decrease when I adjust the
min/max size of the bean pool and restart the server. However the pool only
provides the last three beans that were instantiated for use by the client.

One difference -- would this be significant? -- is my business method is
annotated as @Asynchronous.

Best,
Stuart



On Tue, Jan 7, 2014 at 5:01 AM, Romain Manni-Bucau <rm...@gmail.com>wrote:

> if you have this main:
>
> package org;
>
> import java.util.Properties;
> import java.util.concurrent.ExecutorService;
> import java.util.concurrent.Executors;
> import java.util.concurrent.TimeUnit;
> import javax.ejb.embeddable.EJBContainer;
> import javax.naming.Context;
> import javax.naming.NamingException;
>
> public class Main {
>     public static void main(String[] args) throws
> InterruptedException, NamingException {
>         final EJBContainer c = EJBContainer.createEJBContainer(new
> Properties() {{
>             setProperty("Default Stateless Container.MaxSize", "100");
>         }});
>         final Context ctx = c.getContext();
>         final TestBean bean =
> TestBean.class.cast(ctx.lookup("java:global/test/TestBean"));
>
>         final ExecutorService es = Executors.newFixedThreadPool(100);
>         for (int i = 0; i < 100; i++) {
>             es.submit(new Runnable() {
>                 @Override
>                 public void run() {
>                     bean.foo();
>                 }
>             });
>         }
>         es.shutdown();
>         es.awaitTermination(1, TimeUnit.DAYS);
>         c.close();
>     }
> }
>
>
> with this TestBean:
>
> package org;
>
> import java.util.concurrent.atomic.AtomicInteger;
> import javax.ejb.Stateless;
>
> @Stateless
> public class TestBean {
>     private static final AtomicInteger id = new AtomicInteger(1);
>
>     private int i = id.getAndIncrement();
>     private boolean done = false;
>
>     public void foo() {
>         if (!done) {
>             System.out.println(">>> " + i);
>         }
>         try {
>             Thread.sleep(200);
>         } catch (InterruptedException e) {
>             e.printStackTrace();
>         }
>     }
> }
>
> you get:
>
> >>> 27
> >>> 7
> >>> 35
> >>> 74
> >>> 34
> >>> 88
> >>> 64
> >>> 21
> >>> 63
> >>> 24
> >>> 99
> >>> 57
> >>> 78
> >>> 3
> >>> 36
> >>> 97
> >>> 20
> >>> 86
> >>> 92
> >>> 4
> >>> 96
> >>> 61
> >>> 49
> >>> 47
> >>> 93
> >>> 9
> >>> 22
> >>> 60
> >>> 29
> >>> 13
> >>> 46
> >>> 11
> >>> 66
> >>> 95
> >>> 1
> >>> 68
> >>> 45
> >>> 43
> >>> 54
> >>> 50
> >>> 33
> >>> 44
> >>> 85
> >>> 39
> >>> 79
> >>> 51
> >>> 31
> >>> 87
> >>> 25
> >>> 91
> >>> 42
> >>> 90
> >>> 84
> >>> 59
> >>> 10
> >>> 19
> >>> 62
> >>> 56
> >>> 53
> >>> 6
> >>> 5
> >>> 69
> >>> 83
> >>> 30
> >>> 41
> >>> 26
> >>> 71
> >>> 40
> >>> 67
> >>> 72
> >>> 75
> >>> 23
> >>> 48
> >>> 37
> >>> 38
> >>> 32
> >>> 14
> >>> 8
> >>> 16
> >>> 17
> >>> 12
> >>> 77
> >>> 82
> >>> 89
> >>> 76
> >>> 18
> >>> 70
> >>> 52
> >>> 2
> >>> 100
> >>> 58
> >>> 65
> >>> 94
> >>> 73
> >>> 80
> >>> 55
> >>> 28
> >>> 98
> >>> 15
> >>> 81
>
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
>
>
>
> 2014/1/7 Romain Manni-Bucau <rm...@gmail.com>:
> > Hi
> >
> > did you check in the log your container 'foo' is used for TestBean?
> > can you share a project showing this behavior?
> > Romain Manni-Bucau
> > Twitter: @rmannibucau
> > Blog: http://rmannibucau.wordpress.com/
> > LinkedIn: http://fr.linkedin.com/in/rmannibucau
> > Github: https://github.com/rmannibucau
> >
> >
> >
> > 2014/1/6 Stuart Easterling <st...@gmail.com>:
> >> Hi, I am new to Tomee / OpenEJB.
> >>
> >> I am trying to create a pool of 100 stateless local session beans. I
> have
> >> the following in tomee.xml:
> >>
> >> <Container id="foo" type="STATELESS">
> >>     minSize = 100
> >>     maxSize = 100
> >> </Container>
> >>
> >> In ejb-jar.xml:
> >>
> >> <enterprise-beans>
> >>     <session>
> >>       <ejb-name>TestBean</ejb-name>
> >>       <local-bean/>
> >>       <ejb-class>com.foo.test.TestFooBean</ejb-class>
> >>       <session-type>Stateless</session-type>
> >>       <transaction-type>Bean</transaction-type>
> >>     </session>
> >>   </enterprise-beans>
> >>
> >> It appears that all 100 beans are properly instantiated.
> >>
> >> However, when I attempt to access them, only three bean instances are
> being
> >> provided by the container, even when the invoking code must wait to gain
> >> access to an instance.
> >>
> >> I have looked through and searched the documentation but haven't been
> able
> >> to resolve the problem. Any insights would be greatly appreciated !
> >>
> >> Best,
> >> Stuart
>

Re: stateless bean pool -- all beans not available?

Posted by "Howard W. Smith, Jr." <sm...@gmail.com>.
Also, Stuart, if you look at Romain's code below, Romain is 'not' using
@Asynchronous. So, clearly, @Asynchronous is the cause of the difference in
behavior between your code and Romain's code.



On Tue, Jan 7, 2014 at 5:01 AM, Romain Manni-Bucau <rm...@gmail.com>wrote:

> if you have this main:
>
> package org;
>
> import java.util.Properties;
> import java.util.concurrent.ExecutorService;
> import java.util.concurrent.Executors;
> import java.util.concurrent.TimeUnit;
> import javax.ejb.embeddable.EJBContainer;
> import javax.naming.Context;
> import javax.naming.NamingException;
>
> public class Main {
>     public static void main(String[] args) throws
> InterruptedException, NamingException {
>         final EJBContainer c = EJBContainer.createEJBContainer(new
> Properties() {{
>             setProperty("Default Stateless Container.MaxSize", "100");
>         }});
>         final Context ctx = c.getContext();
>         final TestBean bean =
> TestBean.class.cast(ctx.lookup("java:global/test/TestBean"));
>
>         final ExecutorService es = Executors.newFixedThreadPool(100);
>         for (int i = 0; i < 100; i++) {
>             es.submit(new Runnable() {
>                 @Override
>                 public void run() {
>                     bean.foo();
>                 }
>             });
>         }
>         es.shutdown();
>         es.awaitTermination(1, TimeUnit.DAYS);
>         c.close();
>     }
> }
>
>
> with this TestBean:
>
> package org;
>
> import java.util.concurrent.atomic.AtomicInteger;
> import javax.ejb.Stateless;
>
> @Stateless
> public class TestBean {
>     private static final AtomicInteger id = new AtomicInteger(1);
>
>     private int i = id.getAndIncrement();
>     private boolean done = false;
>
>     public void foo() {
>         if (!done) {
>             System.out.println(">>> " + i);
>         }
>         try {
>             Thread.sleep(200);
>         } catch (InterruptedException e) {
>             e.printStackTrace();
>         }
>     }
> }
>
> you get:
>
> >>> 27
> >>> 7
> >>> 35
> >>> 74
> >>> 34
> >>> 88
> >>> 64
> >>> 21
> >>> 63
> >>> 24
> >>> 99
> >>> 57
> >>> 78
> >>> 3
> >>> 36
> >>> 97
> >>> 20
> >>> 86
> >>> 92
> >>> 4
> >>> 96
> >>> 61
> >>> 49
> >>> 47
> >>> 93
> >>> 9
> >>> 22
> >>> 60
> >>> 29
> >>> 13
> >>> 46
> >>> 11
> >>> 66
> >>> 95
> >>> 1
> >>> 68
> >>> 45
> >>> 43
> >>> 54
> >>> 50
> >>> 33
> >>> 44
> >>> 85
> >>> 39
> >>> 79
> >>> 51
> >>> 31
> >>> 87
> >>> 25
> >>> 91
> >>> 42
> >>> 90
> >>> 84
> >>> 59
> >>> 10
> >>> 19
> >>> 62
> >>> 56
> >>> 53
> >>> 6
> >>> 5
> >>> 69
> >>> 83
> >>> 30
> >>> 41
> >>> 26
> >>> 71
> >>> 40
> >>> 67
> >>> 72
> >>> 75
> >>> 23
> >>> 48
> >>> 37
> >>> 38
> >>> 32
> >>> 14
> >>> 8
> >>> 16
> >>> 17
> >>> 12
> >>> 77
> >>> 82
> >>> 89
> >>> 76
> >>> 18
> >>> 70
> >>> 52
> >>> 2
> >>> 100
> >>> 58
> >>> 65
> >>> 94
> >>> 73
> >>> 80
> >>> 55
> >>> 28
> >>> 98
> >>> 15
> >>> 81
>
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
>
>
>
> 2014/1/7 Romain Manni-Bucau <rm...@gmail.com>:
> > Hi
> >
> > did you check in the log your container 'foo' is used for TestBean?
> > can you share a project showing this behavior?
> > Romain Manni-Bucau
> > Twitter: @rmannibucau
> > Blog: http://rmannibucau.wordpress.com/
> > LinkedIn: http://fr.linkedin.com/in/rmannibucau
> > Github: https://github.com/rmannibucau
> >
> >
> >
> > 2014/1/6 Stuart Easterling <st...@gmail.com>:
> >> Hi, I am new to Tomee / OpenEJB.
> >>
> >> I am trying to create a pool of 100 stateless local session beans. I
> have
> >> the following in tomee.xml:
> >>
> >> <Container id="foo" type="STATELESS">
> >>     minSize = 100
> >>     maxSize = 100
> >> </Container>
> >>
> >> In ejb-jar.xml:
> >>
> >> <enterprise-beans>
> >>     <session>
> >>       <ejb-name>TestBean</ejb-name>
> >>       <local-bean/>
> >>       <ejb-class>com.foo.test.TestFooBean</ejb-class>
> >>       <session-type>Stateless</session-type>
> >>       <transaction-type>Bean</transaction-type>
> >>     </session>
> >>   </enterprise-beans>
> >>
> >> It appears that all 100 beans are properly instantiated.
> >>
> >> However, when I attempt to access them, only three bean instances are
> being
> >> provided by the container, even when the invoking code must wait to gain
> >> access to an instance.
> >>
> >> I have looked through and searched the documentation but haven't been
> able
> >> to resolve the problem. Any insights would be greatly appreciated !
> >>
> >> Best,
> >> Stuart
>

Re: stateless bean pool -- all beans not available?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
if you have this main:

package org;

import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import javax.ejb.embeddable.EJBContainer;
import javax.naming.Context;
import javax.naming.NamingException;

public class Main {
    public static void main(String[] args) throws
InterruptedException, NamingException {
        final EJBContainer c = EJBContainer.createEJBContainer(new
Properties() {{
            setProperty("Default Stateless Container.MaxSize", "100");
        }});
        final Context ctx = c.getContext();
        final TestBean bean =
TestBean.class.cast(ctx.lookup("java:global/test/TestBean"));

        final ExecutorService es = Executors.newFixedThreadPool(100);
        for (int i = 0; i < 100; i++) {
            es.submit(new Runnable() {
                @Override
                public void run() {
                    bean.foo();
                }
            });
        }
        es.shutdown();
        es.awaitTermination(1, TimeUnit.DAYS);
        c.close();
    }
}


with this TestBean:

package org;

import java.util.concurrent.atomic.AtomicInteger;
import javax.ejb.Stateless;

@Stateless
public class TestBean {
    private static final AtomicInteger id = new AtomicInteger(1);

    private int i = id.getAndIncrement();
    private boolean done = false;

    public void foo() {
        if (!done) {
            System.out.println(">>> " + i);
        }
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

you get:

>>> 27
>>> 7
>>> 35
>>> 74
>>> 34
>>> 88
>>> 64
>>> 21
>>> 63
>>> 24
>>> 99
>>> 57
>>> 78
>>> 3
>>> 36
>>> 97
>>> 20
>>> 86
>>> 92
>>> 4
>>> 96
>>> 61
>>> 49
>>> 47
>>> 93
>>> 9
>>> 22
>>> 60
>>> 29
>>> 13
>>> 46
>>> 11
>>> 66
>>> 95
>>> 1
>>> 68
>>> 45
>>> 43
>>> 54
>>> 50
>>> 33
>>> 44
>>> 85
>>> 39
>>> 79
>>> 51
>>> 31
>>> 87
>>> 25
>>> 91
>>> 42
>>> 90
>>> 84
>>> 59
>>> 10
>>> 19
>>> 62
>>> 56
>>> 53
>>> 6
>>> 5
>>> 69
>>> 83
>>> 30
>>> 41
>>> 26
>>> 71
>>> 40
>>> 67
>>> 72
>>> 75
>>> 23
>>> 48
>>> 37
>>> 38
>>> 32
>>> 14
>>> 8
>>> 16
>>> 17
>>> 12
>>> 77
>>> 82
>>> 89
>>> 76
>>> 18
>>> 70
>>> 52
>>> 2
>>> 100
>>> 58
>>> 65
>>> 94
>>> 73
>>> 80
>>> 55
>>> 28
>>> 98
>>> 15
>>> 81

Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau



2014/1/7 Romain Manni-Bucau <rm...@gmail.com>:
> Hi
>
> did you check in the log your container 'foo' is used for TestBean?
> can you share a project showing this behavior?
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
>
>
>
> 2014/1/6 Stuart Easterling <st...@gmail.com>:
>> Hi, I am new to Tomee / OpenEJB.
>>
>> I am trying to create a pool of 100 stateless local session beans. I have
>> the following in tomee.xml:
>>
>> <Container id="foo" type="STATELESS">
>>     minSize = 100
>>     maxSize = 100
>> </Container>
>>
>> In ejb-jar.xml:
>>
>> <enterprise-beans>
>>     <session>
>>       <ejb-name>TestBean</ejb-name>
>>       <local-bean/>
>>       <ejb-class>com.foo.test.TestFooBean</ejb-class>
>>       <session-type>Stateless</session-type>
>>       <transaction-type>Bean</transaction-type>
>>     </session>
>>   </enterprise-beans>
>>
>> It appears that all 100 beans are properly instantiated.
>>
>> However, when I attempt to access them, only three bean instances are being
>> provided by the container, even when the invoking code must wait to gain
>> access to an instance.
>>
>> I have looked through and searched the documentation but haven't been able
>> to resolve the problem. Any insights would be greatly appreciated !
>>
>> Best,
>> Stuart

Re: stateless bean pool -- all beans not available?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi

did you check in the log your container 'foo' is used for TestBean?
can you share a project showing this behavior?
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau



2014/1/6 Stuart Easterling <st...@gmail.com>:
> Hi, I am new to Tomee / OpenEJB.
>
> I am trying to create a pool of 100 stateless local session beans. I have
> the following in tomee.xml:
>
> <Container id="foo" type="STATELESS">
>     minSize = 100
>     maxSize = 100
> </Container>
>
> In ejb-jar.xml:
>
> <enterprise-beans>
>     <session>
>       <ejb-name>TestBean</ejb-name>
>       <local-bean/>
>       <ejb-class>com.foo.test.TestFooBean</ejb-class>
>       <session-type>Stateless</session-type>
>       <transaction-type>Bean</transaction-type>
>     </session>
>   </enterprise-beans>
>
> It appears that all 100 beans are properly instantiated.
>
> However, when I attempt to access them, only three bean instances are being
> provided by the container, even when the invoking code must wait to gain
> access to an instance.
>
> I have looked through and searched the documentation but haven't been able
> to resolve the problem. Any insights would be greatly appreciated !
>
> Best,
> Stuart