• Post Reply Bookmark Topic Watch Topic
  • New Topic

EJB activation/'passivation'

 
lesley evensen
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have only read about these topics, on the java Sun J2EE tutorial, so hope someone who's used them may answer: is the purpose of 'passivation' (ejbPassivate() ) simply to return a bean to the pool (resource management)? and since you haven't 'removed' it, why would you ever explicitly 'passivate' a bean- when you call 'create' or 'activate', presumably you will initialize values for that instance, establish a primary key, whatever; if your container is passivating objects that haven't been accessed for a period of time, isn't that consuming resources, too? And what is this 'secondary memory' storage the J2EE tutorial mentioned? If the object is not destroyed, memory is not released - if you explicitly invoke 'passivate', what is the benefit? ('passivate' my eye- not a fan of nebulous neologisms)
Thanks for your attention!
 
Jorge Phillips
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Passivation is a mechanism to release main memory occupied by a bean, while preserving its state for next time it is used. It kicks in whenever main memory in your EJB server has been depleted and room is needed to create or activate another bean instance. An analogous mechanism is page management in a virtual store. Pages are used by processes, and are written to disk (passivated?) whenever memory is full and they have not been used for a while by the owning process (LRU). Secondary memory normally refers to disk-based memory storage.
[This message has been edited by Jorge Phillips (edited December 11, 2001).]
 
lesley evensen
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Jorge - in your analogy, page-swapping makes sense but usually the app isn't handling pages - for VM mgmt, an OS is swapping pages in and out for you; by that token, should you let the EJB server handle 'passivation' and not the code in your application?
If you serialize out the data (write to disk), then you'd expect that bean to be 'passivated' If 'passivating' means the instance-data is cleared, but state is maintained, how much memory is actually released? Is there any reason to invoke 'passivate' in your app, and have the container also checking for beans that can be 'passivated'? I am wondering about the efficiency of this model..
thank you again for your quick response.
 
Manjunath Subramanian
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi lesley ,
Lets assume you have a Shopping cart Application.
Assume that the Application server can handle a maximum of 100
concurrent users(for simplicity sake).A new customer logs in.
The app server needs to create a new instance which will cater
to his service.But there is no room to create a new instance.
So what the application server does is it tries to locate that bean instance which is idle fo the longest amount of time.Takes the values it is populated with and saves it along with the session context or entity context in a secondary storage(hard disk)inside a file.Then it creates a new bean instance for the recent request.This process is known as passivation and it happens in rare situations.
And at sometime later when the ole bean instance is required then a bean is picked up from the waiting pool and it is populated with the values from the file which the app server had earlier created.This is known as Activation.
The purpose of ejbActivate and ejbPassivate is to perform certain operations like closing connections, settings references to null etc.The purpose of ejbActivate is to set up the bean by say populating it with values required for computation.
Hope this helps,
Manjunath
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!