tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Marco.Hu...@partner.bmw.ch>
Subject AW: Are stateful session beans cached?
Date Thu, 26 Feb 2009 10:20:09 GMT
Hi Jonathan,

Thank you for your study and for your time. The solution was simple as it can be and I could
knock my head against the wall that I didn't see the problem yesterday.
All works correcly, but I missed something as I investigated the problem. The session bean
I wanted to access was within a stateless session bean. So for that it's clear that @PostConstruct
of the stateful reference is only invoked once inside a stateless session bean. My JNDI lookups
were only at the stateless bean.

Thank you again for your time,
Marco

-----Urspr√ľngliche Nachricht-----
Von: Jonathan Gallimore [mailto:jonathan.gallimore@gmail.com]
Gesendet: Donnerstag, 26. Februar 2009 00:06
An: users@openejb.apache.org
Betreff: Re: Are stateful session beans cached?

I investigated this using the simple-stateful example, and I added these methods to CounterImpl:

    public CounterImpl() {
        System.out.println("Construct");
    }

    @PostConstruct
    void postConstruct() {
        System.out.println("PostConstruct");
    }

and added a simple loop to the test:

    public void testCounterViaRemoteInterface() throws Exception {
        for (int i = 0; i < 10; i++) {
            Object object = initialContext.lookup("CounterImplRemote");

            assertNotNull(object);
            assertTrue(object instanceof CounterRemote);
            CounterRemote counter = (CounterRemote) object;
            assertEquals(0, counter.reset());
            assertEquals(1, counter.increment());
            assertEquals(2, counter.increment());
            assertEquals(0, counter.reset());
        }
    }


The result for me was that both the constructor and PostConstruct method were both invoked
10 times.

Are you able to share your client code to give us a better idea of what's going on?

Cheers

Jon


Marco.Huber@partner.bmw.ch wrote:
> Hi all,
>
> I have a stateful session bean with a @PostConstruct method.
>
> @Stateful
> public class MyStatefulBeanImpl implements MyStatefulBean {
>
>         public ProcessContextImpl() {
>                 log.info("CREATE NEW MyStatefulBeanImpl ...");
>         }
>
>         @PostConstruct
>         public void init() {
>                 log.info("Init ...");
>                 ...
>         }
>
>
> So now I'm wondering why the post construct is invoked only at the first time I use such
kind of stateful session bean.
> A second lookup over JNDI or using of the @EJB annotation in an other SB doesn't call
neither the constructor nor the post construct method.
> The logging statement are only once in my whole log file.
>
> I know there is cache for stateless session beans, but is there also one for stateful
session beans? Or do I miss something.
>
> Thank you for your help
>
> Marco
>


Mime
View raw message