tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jonathan Gallimore <jonathan.gallim...@gmail.com>
Subject Re: Are stateful session beans cached?
Date Wed, 25 Feb 2009 23:05:41 GMT
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
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message