• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

ejbCreate() Stateless Session Bean

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am a bit confused about the callback method ejbCreate() for a stateless session bean . When you call create() what you got is the EJBObject stub
which isn't tied to a particular bean instance , the bean comess out of the pool only when a business method is called .

My doubt is during this entire process when the container calls ejbCreate() ?


Am i missing something .

Thanks in advance.

Regards,
Mohit.
 
Mohit Agarwal
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some more points i like to add is that for stateless session bean , the object instances can be created any time , means its upto the container what it chosses . So during a create() call , there is no association with a object instance .

Thats where i start to get confused .....

Regards,
Mohit.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stateless session beans arent tied to any client, so even when you call create() on your home interface ejbCreate() will not be called.

More clearly, the container maintains a free pool of beans and most containers have XML mode configuration to control this pool as to how many beans should be in free pool, whether the bean instances should be loaded at the start of the server or as when the load increases.

Try this, get a reference to the bean's home object and then call create() method to get the remote componet, dont call any of the business methods. If you have put a print stmt in ejbCreate() you will not see that output now. Only when you call a business method on your remote interface, you will see the print output.

now try to call the same or different business method with this remote component and again you will not see the print stmt in the ejbCreate() method. so its clear that the ejbCreate() will be called only when the bean is created and after creation and servicing a client request, the bean goes to the free pool and ejbCreate() will never be called again on this bean instance.
 
Mohit Agarwal
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I still have some doubts like :

I follow what i do , calling a business method() on the bean instance , now the print statement in ejbCreate() may or may not be called , reason being it might have been called earlier . In case, its not called , then we will have the print statement on the console.


Now after servicing the method the bean goes back to the pool , now if the client again calls a business method on the same EJBObject stub it might be tied to another bean instance(different from the one obtained earlier) .

So we can never predict that the priont stmt in ejbCreate() will ever be called or not , it may or may not be .

What do you feel ?

Regards,
Mohit.
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
True, you cannot predict when the ejbCreate() method will be invoked. I use JBoss, and I noticed that when I start up the server, it displays the output from the ejbCreate() print statements. So my installation of JBOss was configured to create beans on start up. It all depends on the container and your configuration.
 
Sheriff
Posts: 3064
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think most containers create a pool of the stateless session beans on startup. Usually, the size of the pool is configurable, and in some cases you can allow the pool to grow when needed. I assume if a bean dies (because of an uncaught system exception for example) that most containers will replace it in the pool immediately.

It's not correct to say we can't predict if ejbCreate will be run or not, but it can be tricky to predict exactly when it will be run. It's possible that it could be run as the result of calling a business method as Srinivasan suggests, but that's not likely. Usually, the pool will be in place by that time.
 
reply
    Bookmark Topic Watch Topic
  • New Topic