<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Java Interview Questions &#187; Life cycle of Stateless Session bean</title>
	<atom:link href="http://www.bestjavainterviewquestions.com/category/ejb-interview-questions/life-cycle-of-stateless-session-bean/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bestjavainterviewquestions.com</link>
	<description>Java Interview Questions &#124; Core Java Interview Questions &#124; Advanced Java Interview Questions &#124; EJB Interview Questions &#124; J2EE Interview Questions &#124; Hibernate Interview Questions</description>
	<lastBuildDate>Fri, 30 Jul 2010 06:00:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Life Cycle of stateless session bean</title>
		<link>http://www.bestjavainterviewquestions.com/life-cycle-of-stateless-session-bean/</link>
		<comments>http://www.bestjavainterviewquestions.com/life-cycle-of-stateless-session-bean/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 19:27:09 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Life cycle of Stateless Session bean]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=559</guid>
		<description><![CDATA[Stateless session bean The stateless session beans life cycle has two states: does not exist state and the method ready pool Does not exist When a bean instance is in the does not exist state, it is not an instance in the momory of the system.In other words, it has not been instantiated yet. The [...]]]></description>
			<content:encoded><![CDATA[<p><em><strong>Stateless session bean</strong></em></p>
<p><em>The stateless session beans life cycle has two states:</em></p>
<ol>
<li>does not exist state and</li>
<li>the method ready pool</li>
</ol>
<p><strong>Does not exist</strong></p>
<p>When a bean instance is in the does not exist state, it is not an instance in the momory of the system.In other words, it has not been instantiated yet.</p>
<p><strong>The method ready pool</strong></p>
<p>Stateless bean instances enter the Method-Ready pool, as the container needs them. When the EJB server is first started, it will create a number of stateless bean instances and enter them into the Method-Ready pool, (The actual behavior of the server depends on the implementation). When the number of stateless instances servicing client request is insufficient, more can be created and added to the pool.</p>
<p><strong>Transitioning to the method-ready pool</strong></p>
<p>When an instance transitions from the Does Not Exist state to the Method-Ready pool, three operations are performed on it. First, the bean instance is instantiated by invoking the <strong>Class.newInstance()</strong> method on the stateless bean class.</p>
<p>Second, the session bean&#8217;s <strong>setSessionContext(SessionContext context)</strong> method is invoked on the bean instance. This is when the instance receives its reference to the EJBContext for its lifetime. The SessionContext reference may be stored in a <strong>nonTransient </strong>instance field of the stateless session bean.</p>
<p>Finally, the no-argument <strong>ejbCreate()</strong> method is invoked on the bean instance. Remember that a stateless session bean only has one <strong>ejbCreate() </strong>method is invoked only once in the life cycle of the stateless session bean, when the client invokes the <strong>create()</strong> method on the EJB home, it is not delegated to the bean instance.</p>
<p>Stateless session beans are not subject to activation, so they can maintain open connections to resources for their entire life cycle. The <strong>ejbRemove() </strong>method should close any open resources before the stateless session bean is removed from memory at the end of its life cycle.</p>
<p><strong>Life in the Method-Ready Pool:</strong></p>
<p>Once an instance is in the Method-Ready pool,  it is ready to service client requests. When a client invokes a business method on an EJB object, the method call is delegated to any available instance in the Method-Ready pool. While the instance is executing the request, it is unavailable for use by other EJB objects. Once the instance has finished, it is immediately available to any EJB object then needs it.</p>
<p>Stateless session instances are only dedicated to an EJB object for the duration of the method. When  an instance is swapped in, its <strong>SessionContext </strong>changes to reflect the context of its EJB object and the client invoking the mehtod. The bean instance may be included in the transactional scope of the client&#8217;s request, and it may access <strong>SessionContext </strong>information specific to the client requested for example, the security and transactional methods. Once the instance has finished servicing the client, it is disassociated from the EJB object and returned to the Method-Ready pool.</p>
<p><strong>Transitioning out of the Method-Ready-Pool</strong></p>
<p>(The death of a stateless bean instance)</p>
<p>Bean instances leave the Method-Ready pool for does Not Exist state when the server no longer needs the instance. This occurs when the server decides to reduce the total size of the Method-Ready pool by removing one or more instance from memory. The process begins by invoking the<strong> ejbRemove() </strong>method on the instance. At this time, the bean instance should perform any cleanup operations, like closing open resources. The<strong> ejbRemove()</strong> method is only invoked once in the life cycle of a stateless session bean&#8217;s instance, whenit is about to make a transition to the does not exist state. When a client invokes one of the<strong> remove()</strong> method on a stateless bean&#8217;s remote or home interface, it is not delegated to the bean instance. The client&#8217;s invocations of this method simply invalidates the <strong>stub </strong>and releases the EJB object, it notifies the container that the client no longer needs the bean. The container itself invokes the <strong>ejbRemove() </strong>method on the stateless  instance, but only at the end of the instance&#8217;s life cycle.</p>
<p>During the <strong>ejbRemove() </strong>method, the <strong>SessionContext </strong>is still available to the bean istance. Following the execution of the <strong>ejbRemove()</strong> method, the bean is dereferenced and eventually garbage collected.</p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li><a href="http://www.bestjavainterviewquestions.com/ejb-interview-questions/" title="EJB INTERVIEW QUESTIONS"><img src="Array" alt="EJB INTERVIEW QUESTIONS" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/how-to-get-a-leap-year/" title="How to get a Leap Year"><img src="Array" alt="How to get a Leap Year" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/providing-current-date-and-time-using-stateless-session-bean/" title="Providing current date and time using Stateless session bean"><img src="Array" alt="Providing current date and time using Stateless session bean" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/what-is-event-delegation-model/" title="What is Event Delegation Model"><img src="Array" alt="What is Event Delegation Model" /></a></li><li><a href="http://www.bestjavainterviewquestions.com/explain-executeupdate-method/" title="Explain executeUpdate Method"><img src="Array" alt="Explain executeUpdate Method" /></a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/life-cycle-of-stateless-session-bean/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
