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