aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Stateful session bean doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Stateful session bean doubt" Watch "Stateful session bean doubt" New topic
Author

Stateful session bean doubt

Deepak Jain
Ranch Hand

Joined: Aug 05, 2006
Posts: 637
EJB in Action code example chapter 3 User account creation.

I invoked createAccount() which is not marked with @Remove annotation, from the client code. As a result of the JNDI lookup
a new instance of the bean is created and PostConstruct callback is invoked as shown below.

20:49:51,359 INFO [STDOUT] openConnection()
20:49:51,359 INFO [STDOUT] I am callback for PostConstruct events for this stateful session bean
20:49:51,359 INFO [STDOUT] I will be invoked after the bean is instantiated and DI are complete.

I invoked the client code again and i was surprised to see that PostConstruct callback was invoked.
Since the bean is a stateful session bean and client never invoked a buisness method with @Remove and therefore
the bean instance should continue to exists in main memory since the client invocation of the buisness method was
within say 2 seconds.
I was expecting the buisness method createAccount() to be invoked on the same session stateful bean.
20:50:06,796 INFO [STDOUT] openConnection()
20:50:06,796 INFO [STDOUT] I am callback for PostConstruct events for this stateful session bean
20:50:06,796 INFO [STDOUT] I will be invoked after the bean is instantiated and DI are complete.

I kept the client connection idle for atleast 10 minutes and PrePassivate methods were never invoked. How long does one has to wait ?
And is this time configurable from JBOSS ? [My guess is , it should be]


SCJP, SCWCD, SCBCD
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

I invoked the client code again

That's a new client, isn't it ? If the process ends, then your first client is gone. Not the same client, so new bean. What happens if you call createAccount() twice from the same method ?


[My Blog]
All roads lead to JavaRanch
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Stateful session bean doubt