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 <[email protected]>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 <[email protected]>:
> > 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 <[email protected]>:
> >> 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
>

Reply via email to