File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes Lifecycle of EJB Objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Lifecycle of EJB Objects" Watch "Lifecycle of EJB Objects" New topic
Author

Lifecycle of EJB Objects

Piyush Daiya
Ranch Hand

Joined: Jun 13, 2002
Posts: 67
Hi,
Can anyone guide me on lifecycle of EJB Objects?
Is EJB object created for each client request or EJB objects can be shared between two or more client requests?

Waiting for reply,

Piyush


"A scientist is not person who gives right answers but a person who asks right questions"
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1121

Hi Piyush,
The EJB life-cycle is thoroughly explained in both the EJB specification and any good book on EJB (like "Mastering Enterprise JavaBeans" by Ed Roman, or "Enterprise JavaBeans" by Richard Monson-Haefel, or "Enterprise JavaBeans" by Tom Valesky).
What resources (if any) have you read regarding the bean life cycle? Did you have trouble understanding them? Is there a specific aspect of the life cycle that you have a specific question about?
I don't think it would be very helpful if I just repeated the explanation that you can find in all of the resources I mentioned above.
Good Luck,
Avi.
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2771
    
  10

Avi has a good point, but I'll give you a little information, which may be what you are looking for. Stateless session bean and message bean calls are not reentrant, which means that if two clients make calls simultaneously, they will be serviced by two distinct instances of the bean. Once a bean method returns however, the next call, even it is from a different client, may be handled by the same instance of the bean.
Subhash Nambiar
Greenhorn

Joined: Jan 11, 2002
Posts: 26
EJB OBJECTS NEVER GET SWAPPED IT IS THE BEAN INSTANCE WHICH KEEP ON SWAPPING BETWEEN DIFFERENT EJB OBJECT BUT EJBOBJECT ALWAYS BIND TO A CLIENT .
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3879
Originally posted by Subhash Nambiar:
EJB OBJECTS NEVER GET SWAPPED IT IS THE BEAN INSTANCE WHICH KEEP ON SWAPPING BETWEEN DIFFERENT EJB OBJECT BUT EJBOBJECT ALWAYS BIND TO A CLIENT .

Stop yelling! Learn to use the "Caps Lock" key and you will make many more friends.
Kyle


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
Kathy Sierra
Cowgirl and Author
Ranch Hand

Joined: Oct 10, 2002
Posts: 1572
Keep in mind that most of the lifecycle of EJB (in the spec) is more of a "conceptual" model rather than an actual "here is how it is implemented and here are the number of objects, etc.". In other words, the spec tells you how to THINK about the way it works, but how the vendor actually implements it is largely up to the vendor. The spec tells us (the developers) what the container is guaranteed to do -- for behavior -- but we can't always know exactly how many objects they've instantiated to do that work.
For example (but I'm dusting off my very old EJB experience here, so someone more current might have more insight):
* We "think" of entity beans as having at least one EJBObject per each pk that's being used while the container is running. We "think" of the PK as being stored in the EJBObject, since we know the actual entity bean instances themselves are pooled, but how do you tell the container you (the client) are done with the entity bean? There's no explicit mechanism, so while you DO tell the container when you're done with a stateful session bean (remove()), this doesn't apply for entity beans. So people sometimes ask, "what happens to all those entity EJB objects after there aren't any more clients holding an active reference to that particular Component Interface (for that particular entity)?" Answer is, we don't know for sure from the specificaion. So for all we know, with a remote interface, the vendor is storing the PK in the Stub object, rather than the remote (EJBObject). So that there is NOT one EJBObject per entity bean PK that's been requested, even though we can "think" of the lifecycle as though that were true.
Again, forgive me if all of this has been said to death here. I'm just coming back in after a very very long absence.
Kathy (aka cowgirl)


Co-Author of <a href="http://www.amazon.com/exec/obidos/ASIN/0596007124/ref=jranch-20" target="_blank" rel="nofollow">"Head First Design Patterns"</a><br /> <br />Just a Jini girl living in a J2EE world.
Rick Hightower
Author
Ranch Hand

Joined: Feb 20, 2002
Posts: 350
I helped write a Developer's guide to EJB listed in my signature. It is free and it explains the lifecycle well.
Different types of beans have different lifecycles.
For example, an entity bean has a long lifecycle as it represents persistent state, i.e., like a row in a database.
A stateful session bean is created when the end user session begins, and remains untill the session ends. It holds conversational state for the client session.
A stateless session bean can live or die outside of a particular session because it does not have affinity to a single client like a stateful Session bean. Ditto for MDB.
For more details, see the free developer's guide to EJB listed in my signature.


Rick Hightower is CTO of Mammatus which focuses on Cloud Computing, EC2, etc. Rick is invovled in Java CDI and Java EE as well. linkedin,twitter,blog
 
wood burning stoves
 
subject: Lifecycle of EJB Objects
 
Similar Threads
stop() operation of MBean that manage a deployed EJB???
Can a stateless session bean be removed by client?
Administered objects
Passed 95%
new to EJB : EJB 3.0 queries