tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <>
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,

-----Urspr√ľngliche Nachricht-----
Von: Jonathan Gallimore []
Gesendet: Donnerstag, 26. Februar 2009 00:06
Betreff: Re: Are stateful session beans cached?

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

    public CounterImpl() {

    void 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");

            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?


Jon wrote:
> Hi all,
> I have a stateful session bean with a @PostConstruct method.
> @Stateful
> public class MyStatefulBeanImpl implements MyStatefulBean {
>         public ProcessContextImpl() {
>       "CREATE NEW MyStatefulBeanImpl ...");
>         }
>         @PostConstruct
>         public void init() {
>       "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

View raw message