{"id":16302,"date":"2013-08-12T11:46:14","date_gmt":"2013-08-12T08:46:14","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=16302"},"modified":"2013-12-30T22:51:47","modified_gmt":"2013-12-30T20:51:47","slug":"ejb-passivation-and-activation-example","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2013\/08\/ejb-passivation-and-activation-example.html","title":{"rendered":"EJB passivation and activation example"},"content":{"rendered":"<p>In this tutorial we are going to see how activation and passivation works in a Stateful Java Enterprise Session Bean.<\/p>\n<h2>1. Introduction<\/h2>\n<p>Stateful Session Beans usually hold information about a specific client, and holds that information throughout the whole session. It is a fact though, that client sessions tend to be active for a respectable amount of time, and of course many clients can be online the same time. As a result, it is a necessity for the EJB container to implement a mechanism that makes possible the releasing of resources that are not used at a given moment, and can be activated again when needed.<\/p>\n<p>Passivating a Session Bean means removing it from the Session EJB Cache of the container and storing all the necessary information and properties of the session bean in a file. Activating a session bean means reading the aforementioned file and restoring the passivated session bean in the cache. As you might imagine all the fields of a that session bean must be <a href=\"http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/io\/Serializable.html\">Serializable<\/a>.<\/p>\n<p>In this example we are going to create an EAR Project and an EJB Project that will host our Session Bean and a Dynamic Web Application that will host a Servlet, testing the aforementioned passivation and activation properties. We are going to use Eclipse Java EE IDE 4,3 Kepler and Glassfish 4.0 as our container.<\/p>\n<h2>2. Create a new Enterprise Application Project<\/h2>\n<p>Create a new Enterprise Application Project named <code>SatefulBeansEAR<\/code> .In Eclipse IDE select File -&gt; New -&gt; Enterprise Application Project and fill in the form and click Finish:<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/new-ear-project.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-20103\" alt=\"new-ear-project\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/new-ear-project.png\" width=\"525\" height=\"635\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/new-ear-project.png 525w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/new-ear-project-248x300.png 248w\" sizes=\"(max-width: 525px) 100vw, 525px\" \/><\/a><\/p>\n<h2>3. Create a new EJB Projet<\/h2>\n<p>Create a new EJB Project called StatefulEJB. We are going to create our session bean on this. Go to File -&gt; New -&gt; EJB Project and fill out the form. Be careful to select &#8220;Add EAR Project&#8221; and Select &#8220;<code>StatefulBeansEAR<\/code>&#8221; as EAR project name:<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/new-ejb-project.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-20104\" alt=\"new-ejb-project\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/new-ejb-project.png\" width=\"530\" height=\"707\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/new-ejb-project.png 530w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/new-ejb-project-224x300.png 224w\" sizes=\"(max-width: 530px) 100vw, 530px\" \/><\/a><\/p>\n<p>Click Next twice and choose to create EJB Client JAR, as well as to generate the <code>ejb-jar.xml<\/code> deployment descriptor :<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/ejb-client.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-20105\" alt=\"ejb-client\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/ejb-client.png\" width=\"472\" height=\"377\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/ejb-client.png 472w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/ejb-client-300x239.png 300w\" sizes=\"(max-width: 472px) 100vw, 472px\" \/><\/a><\/p>\n<h2>4. Create a Sateful Session Bean<\/h2>\n<p>Open StatefulEJB Project in the Project Explorer and in the folder <code>ejbModule<\/code> create a new source package named <code>com.javacodegeeks.enterprise.ejb<\/code>. In that package create a new Interface that will be a local view of the EJB:<\/p>\n<p><em><span style=\"text-decoration: underline;\">Passivation.java:<\/span><\/em><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.enterprise.ejb;\r\n\r\nimport javax.ejb.Local;\r\n\r\nimport com.javacodegeeks.enterprise.ejb.property.PropertyObject;\r\n\r\n@Local\r\npublic interface Passivation {\r\n\r\n\tvoid setPropertyObject(PropertyObject propertyObject);\r\n\r\n\tPropertyObject getPropertyObject();\r\n\r\n}<\/pre>\n<p>And here is the Session Bean:<\/p>\n<p><em><span style=\"text-decoration: underline;\">PassivationBean.java:<\/span><\/em><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.enterprise.ejb;\r\n\r\nimport javax.ejb.PostActivate;\r\nimport javax.ejb.PrePassivate;\r\nimport javax.ejb.Stateful;\r\n\r\nimport com.javacodegeeks.enterprise.ejb.property.PropertyObject;\r\n\r\n@Stateful\r\npublic class PassivationBean implements Passivation {\r\n\r\n\tprivate PropertyObject myProperty;\r\n\r\n\t@Override\r\n\tpublic void setPropertyObject(PropertyObject propertyObject) {\r\n\t\tthis.myProperty = propertyObject;\r\n\r\n\t}\r\n\r\n\t@Override\r\n\tpublic PropertyObject getPropertyObject() {\r\n\r\n\t\treturn this.myProperty;\r\n\t}\r\n\r\n\t@PrePassivate\r\n\tprivate void prePassivate(){\r\n\t    \/\/ Free resources \r\n\t    \/\/ ...\r\n\r\n\t    System.out.println(\"Passivating EJB. Property value: \" \r\n\t      + myProperty.getProperty());\r\n\t}\r\n\r\n\t@PostActivate\r\n\tprivate void postActivate(){\r\n\t    \/\/ Reactivate resources\r\n\t    \/\/ ...\r\n\r\n\t    System.out.println(\"Activating EJB. Property value: \" \r\n\t      + myProperty.getProperty());\r\n\t}\r\n}<\/pre>\n<p>In the above code :<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<ul>\n<ul>\n<li><strong><code>private void prePassivate()<\/code><\/strong>: Annotated with <code>@PrePassivate<\/code> is the method to be executed when the EJB container decides to passivate that session bean.<\/li>\n<li><strong><code>private void postActivate()<\/code><\/strong>: Annotated with <code>@PostActivate<\/code><\/li>\n<\/ul>\n<\/ul>\n<p>is the method to be executed when the EJB container activates a passivated session bean because it&#8217;s needed again.<\/p>\n<p>Additionally, as you can see the session bean has a <code>private PropertyObject myProperty<\/code> field. This is an object that can contain information for the session, for the bean, for the resources and any kind of data one can find useful.<\/p>\n<p>So when the bean is passivated we want this property has to be saved and restored as well. Thus, it must be <code>Serilizable<\/code> as we mentioned in the Introduction. Having said that, if you don&#8217;t want to store this property, because you don&#8217;t care to retrieve that resource when the bean is activated, you can declare the object transient using the <code>@Transient<\/code> annotation . For this Object I&#8217;ve created a new source Package named <code>com.javacodegeeks.enterprise.ejb.property<\/code>.<\/p>\n<p><em><span style=\"text-decoration: underline;\">PropertyObject.java:<\/span><\/em><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.enterprise.ejb.property;\r\n\r\nimport java.io.Serializable;\r\n\r\npublic class PropertyObject implements  Serializable  {\r\n\r\n\tprivate static final long serialVersionUID = 1L;\r\n\r\n\t private String property;\r\n\r\n\tpublic PropertyObject(String value){\r\n\t    this.property = value;\r\n\t  }\r\n\r\n\t  public String getProperty() {\r\n\t    return property;\r\n\t  }\r\n\r\n}<\/pre>\n<p>So this would be the final structure of the EJB project <code>SatefulEJB<\/code>:<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/project-structure.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-20107\" alt=\"project-structure\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/project-structure.png\" width=\"360\" height=\"405\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/project-structure.png 360w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/project-structure-266x300.png 266w\" sizes=\"(max-width: 360px) 100vw, 360px\" \/><\/a><\/p>\n<h2>5. Create a new Dynamic Web Project<\/h2>\n<p>Go to File -&gt; New -&gt; Dynamic Web Project. Fill out the form and make sure you check &#8220;Add project to an EAR&#8221; and put StatefulBeans EAR as the &#8220;EAR project name&#8221;:<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/new-dynamic-web-project.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-20108\" alt=\"new-dynamic-web-project\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/new-dynamic-web-project.png\" width=\"589\" height=\"713\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/new-dynamic-web-project.png 589w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/new-dynamic-web-project-247x300.png 247w\" sizes=\"(max-width: 589px) 100vw, 589px\" \/><\/a><\/p>\n<p>After clicking &#8220;Finish&#8221;, go to the project Explorer and Right click on the Project <code>StatefulBeansTest<\/code> and go to Properties-&gt; Deployment Assembly -&gt; Add -&gt; Porject -&gt; StatefulEJB :<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/deployment-assembly.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-20109\" alt=\"deployment-assembly\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/deployment-assembly.png\" width=\"647\" height=\"429\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/deployment-assembly.png 647w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/deployment-assembly-300x198.png 300w\" sizes=\"(max-width: 647px) 100vw, 647px\" \/><\/a><\/p>\n<h2>6. Create a new Servlet<\/h2>\n<p>Go to <code>StatefulBeansTest<\/code> Web project and create a new Servlet named <code>MyServlet<\/code>:<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/new-servlet.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-20110\" alt=\"new-servlet\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/new-servlet.png\" width=\"525\" height=\"434\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/new-servlet.png 525w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/new-servlet-300x248.png 300w\" sizes=\"(max-width: 525px) 100vw, 525px\" \/><\/a><\/p>\n<p>So this would be the final structure of the Web Project :<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/dynamic-web-projecct-structure.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-20114\" alt=\"dynamic-web-projecct-structure\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/dynamic-web-projecct-structure.png\" width=\"368\" height=\"306\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/dynamic-web-projecct-structure.png 368w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/dynamic-web-projecct-structure-300x249.png 300w\" sizes=\"(max-width: 368px) 100vw, 368px\" \/><\/a><\/p>\n<p><em><span style=\"text-decoration: underline;\">MyServlet.java:<\/span><\/em><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.enterprise.servlet;\r\n\r\nimport java.io.IOException;\r\n\r\nimport javax.naming.InitialContext;\r\nimport javax.servlet.ServletException;\r\nimport javax.servlet.annotation.WebServlet;\r\nimport javax.servlet.http.HttpServlet;\r\nimport javax.servlet.http.HttpServletRequest;\r\nimport javax.servlet.http.HttpServletResponse;\r\n\r\nimport com.javacodegeeks.enterprise.ejb.Passivation;\r\nimport com.javacodegeeks.enterprise.ejb.property.PropertyObject;\r\n\r\n@WebServlet(\"\/MyServlet\")\r\npublic class MyServlet extends HttpServlet {\r\n\r\n\tprivate static final long serialVersionUID = 1L;\r\n\r\n\tpublic MyServlet() {\r\n\t\tsuper();\r\n\r\n\t}\r\n\r\n\tprotected void doGet(HttpServletRequest request,\r\n\r\n\t\tHttpServletResponse response) throws ServletException, IOException {\r\n\r\n\t\tSystem.out.println(\"Hello from Servlet\");\r\n\r\n\t\tInitialContext ic;\r\n\r\n\t\tPassivation passivation;\r\n\r\n\t\tString beanCountparam = request.getParameter(\"count\");\r\n\r\n\t\tif (beanCountparam != null) {\r\n\t\t\tint beanCount = Integer.parseInt(beanCountparam);\r\n\r\n\t\t\ttry {\r\n\t\t\t\tic = new InitialContext();\r\n\t\t\t\tfor (int i = 0; i &lt; beanCount; i++) {\r\n\r\n\t\t\t\t\tpassivation = (Passivation) ic\r\n\t\t\t\t\t\t\t.lookup(\"java:global\/StatefulBeansEAR\/StatefulEJB\/PassivationBean!\"\r\n\t\t\t\t\t\t\t\t\t+ \"com.javacodegeeks.enterprise.ejb.Passivation\");\r\n\r\n\t\t\t\t\tpassivation.setPropertyObject(new PropertyObject(\r\n\t\t\t\t\t\t\t\"bean\" + i));\r\n\r\n\t\t\t\t\trequest.getSession().setAttribute(\"bean\" + i,\r\n\t\t\t\t\t\t\tpassivation);\r\n\t\t\t\t}\r\n\t\t\t} catch (Exception e) {\r\n\t\t\t\tthrow new ServletException(e);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tString beanActivationIndex = request.getParameter(\"activate\");\r\n\r\n\t\tif (beanActivationIndex != null) {\r\n\t\t\ttry {\r\n\t\t\t\tic = new InitialContext();\r\n\r\n\t\t\t\tpassivation = (Passivation) request.getSession()\r\n\t\t\t\t\t\t.getAttribute(\"bean\" + beanActivationIndex);\r\n\r\n\t\t\t\tSystem.out.println(\"TestObject property value: \"\r\n\t\t\t\t\t\t+ passivation.getPropertyObject().getProperty());\r\n\r\n\t\t\t} catch (Exception e) {\r\n\t\t\t\tthrow new ServletException(e);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tprotected void doPost(HttpServletRequest request,\r\n\t\t\tHttpServletResponse response) throws ServletException, IOException {\r\n\t}\r\n\r\n}<\/pre>\n<p>In the above code, when the Servlet is accessed, it parses the <code>count<\/code> query parameter, generates <code>count<\/code> session beans and stores them to the request session. Accordingly, if the <code>activate<\/code> query parameter is present the corresponding bean is retrieved from the session.<\/p>\n<p><strong>Tip:<\/strong><em> If you are having trouble figuring out the\u00a0Portable JNDI names for EJB PassivationObject look at the logs or output of Glassfish when deploying the project and you will find a line like this :<\/em><em><span style=\"text-decoration: underline;\">2013-12-13T18:22:28.598+0200|INFO: EJB5181:Portable JNDI names for EJB PassivationObject: (java:global\/StatefulBeans\/StatefulEJB\/PassivationObject, java:global\/StatefulBeans\/StatefulEJB\/PassivationObject!com.javacodegeeks.enterprise.ejb.Passivation)<\/span><\/em><\/p>\n<h2>7. Test<\/h2>\n<p>After creating the above projects you have to Run <code>StatefulBeansTest<\/code> on Glassfish.<\/p>\n<p>To test the desired behavior, we have to somehow trigger the passivation and activation of a certain session bean. To force a Session bean to be passivated we have to make the container remove it from the session cache. Glassfish can host 512 session beans at most, by default. So if we trigger a request asking for 600 beans to be created, some of them will be eventually removed from the cache.<\/p>\n<p>This request can be :<\/p>\n<pre class=\"brush:bash\">http:\/\/localhost:8080\/StatefulBeansTest\/MyServlet?count=600<\/pre>\n<p>And the output in the console will be :<\/p>\n<pre style=\"background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;\"><code style=\"color: black; word-wrap: normal;\">2013-12-30T22:29:36.978+0200|INFO: Hello from Servlet\r\n2013-12-30T22:29:37.315+0200|INFO: Passivating EJB. Property value: bean31\r\n2013-12-30T22:29:37.329+0200|INFO: Passivating EJB. Property value: bean64\r\n2013-12-30T22:29:37.332+0200|INFO: Passivating EJB. Property value: bean70\r\n2013-12-30T22:29:37.345+0200|INFO: Passivating EJB. Property value: bean98\r\n2013-12-30T22:29:37.390+0200|INFO: Passivating EJB. Property value: bean117\r\n2013-12-30T22:29:37.390+0200|INFO: Passivating EJB. Property value: bean116\r\n2013-12-30T22:29:37.390+0200|INFO: Passivating EJB. Property value: bean115\r\n2013-12-30T22:29:37.394+0200|INFO: Passivating EJB. Property value: bean114\r\n2013-12-30T22:29:37.394+0200|INFO: Passivating EJB. Property value: bean113\r\n2013-12-30T22:29:37.394+0200|INFO: Passivating EJB. Property value: bean112\r\n2013-12-30T22:29:37.397+0200|INFO: Passivating EJB. Property value: bean111\r\n2013-12-30T22:29:37.398+0200|INFO: Passivating EJB. Property value: bean110\r\n2013-12-30T22:29:37.399+0200|INFO: Passivating EJB. Property value: bean109\r\n2013-12-30T22:29:37.402+0200|INFO: Passivating EJB. Property value: bean108\r\n2013-12-30T22:29:37.403+0200|INFO: Passivating EJB. Property value: bean107\r\n.\r\n.\r\n.\r\n<\/code><\/pre>\n<p>So as you can see some of the beans are removed from the cache and thus get passivated. Now to trigger the activation of a bean we can simply request to retrieve a bean that is already passivated, for example <code>bean31<\/code>.<\/p>\n<p>This request can be:<\/p>\n<pre class=\"brush:bash\">http:\/\/localhost:8080\/StatefulBeansTest\/MyServlet?activate=31<\/pre>\n<p>And the output in the console will be :<\/p>\n<pre style=\"background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;\"><code style=\"color: black; word-wrap: normal;\">2013-12-30T22:33:48.742+0200|INFO: Hello from Servlet\r\n2013-12-30T22:33:48.744+0200|INFO: Activating EJB. Property value: bean31\r\n2013-12-30T22:33:48.745+0200|INFO: TestObject property value: bean31<\/code><\/pre>\n<p>That&#8217;s it. Now to be convinced that the session beans we actually serialized to the disc you can go to <code>Glassfish_installation_folder\/glassfish4\/glassfish\/domains\/domain1\/session-store<\/code> where you can actually see the folder that the beans were saved:<\/p>\n<p><a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/session-store.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-20115\" alt=\"session-store\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/session-store.png\" width=\"789\" height=\"487\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/session-store.png 789w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/session-store-300x185.png 300w\" sizes=\"(max-width: 789px) 100vw, 789px\" \/><\/a><\/p>\n<h2>Download Eclipse Project<\/h2>\n<p>This was an example on EJB passivation and activation. Download the Eclipse Project of this tutorial : <a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2013\/08\/EJBPassivationActivation.zip\">EJBPassivationActivation.zip<\/a> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial we are going to see how activation and passivation works in a Stateful Java Enterprise Session Bean. 1. Introduction Stateful Session Beans usually hold information about a specific client, and holds that information throughout the whole session. It is a fact though, that client sessions tend to be active for a respectable &hellip;<\/p>\n","protected":false},"author":7,"featured_media":112,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[90],"class_list":["post-16302","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-ejb"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>EJB passivation and activation example<\/title>\n<meta name=\"description\" content=\"In this tutorial we are going to see how activation and passivation works in a Stateful Java Enterprise Session Bean. 1. Introduction Stateful Session\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2013\/08\/ejb-passivation-and-activation-example.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"EJB passivation and activation example\" \/>\n<meta property=\"og:description\" content=\"In this tutorial we are going to see how activation and passivation works in a Stateful Java Enterprise Session Bean. 1. Introduction Stateful Session\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2013\/08\/ejb-passivation-and-activation-example.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2013-08-12T08:46:14+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-12-30T20:51:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Nikos Maravitsas\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nikos Maravitsas\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/ejb-passivation-and-activation-example.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/ejb-passivation-and-activation-example.html\"},\"author\":{\"name\":\"Nikos Maravitsas\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/aca65ecdda8de63ce629d2754da61f11\"},\"headline\":\"EJB passivation and activation example\",\"datePublished\":\"2013-08-12T08:46:14+00:00\",\"dateModified\":\"2013-12-30T20:51:47+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/ejb-passivation-and-activation-example.html\"},\"wordCount\":941,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/ejb-passivation-and-activation-example.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"keywords\":[\"EJB\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/ejb-passivation-and-activation-example.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/ejb-passivation-and-activation-example.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/ejb-passivation-and-activation-example.html\",\"name\":\"EJB passivation and activation example\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/ejb-passivation-and-activation-example.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/ejb-passivation-and-activation-example.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"datePublished\":\"2013-08-12T08:46:14+00:00\",\"dateModified\":\"2013-12-30T20:51:47+00:00\",\"description\":\"In this tutorial we are going to see how activation and passivation works in a Stateful Java Enterprise Session Bean. 1. Introduction Stateful Session\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/ejb-passivation-and-activation-example.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/ejb-passivation-and-activation-example.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/ejb-passivation-and-activation-example.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/enterprise-java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"java-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2013\\\/08\\\/ejb-passivation-and-activation-example.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"EJB passivation and activation example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/aca65ecdda8de63ce629d2754da61f11\",\"name\":\"Nikos Maravitsas\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3969f52bbf541170fe1ae074a6848e1085b8180438db323f626a436a7d19b23f?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3969f52bbf541170fe1ae074a6848e1085b8180438db323f626a436a7d19b23f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3969f52bbf541170fe1ae074a6848e1085b8180438db323f626a436a7d19b23f?s=96&d=mm&r=g\",\"caption\":\"Nikos Maravitsas\"},\"description\":\"Nikos has graduated from the Department of Informatics and Telecommunications of The National and Kapodistrian University of Athens.\",\"sameAs\":[\"http:\\\/\\\/www.javacodegeeks.com\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/nikos-maravitsas\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"EJB passivation and activation example","description":"In this tutorial we are going to see how activation and passivation works in a Stateful Java Enterprise Session Bean. 1. Introduction Stateful Session","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2013\/08\/ejb-passivation-and-activation-example.html","og_locale":"en_US","og_type":"article","og_title":"EJB passivation and activation example","og_description":"In this tutorial we are going to see how activation and passivation works in a Stateful Java Enterprise Session Bean. 1. Introduction Stateful Session","og_url":"https:\/\/www.javacodegeeks.com\/2013\/08\/ejb-passivation-and-activation-example.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2013-08-12T08:46:14+00:00","article_modified_time":"2013-12-30T20:51:47+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","type":"image\/jpeg"}],"author":"Nikos Maravitsas","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Nikos Maravitsas","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2013\/08\/ejb-passivation-and-activation-example.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/08\/ejb-passivation-and-activation-example.html"},"author":{"name":"Nikos Maravitsas","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/aca65ecdda8de63ce629d2754da61f11"},"headline":"EJB passivation and activation example","datePublished":"2013-08-12T08:46:14+00:00","dateModified":"2013-12-30T20:51:47+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/08\/ejb-passivation-and-activation-example.html"},"wordCount":941,"commentCount":2,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/08\/ejb-passivation-and-activation-example.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","keywords":["EJB"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2013\/08\/ejb-passivation-and-activation-example.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2013\/08\/ejb-passivation-and-activation-example.html","url":"https:\/\/www.javacodegeeks.com\/2013\/08\/ejb-passivation-and-activation-example.html","name":"EJB passivation and activation example","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/08\/ejb-passivation-and-activation-example.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/08\/ejb-passivation-and-activation-example.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","datePublished":"2013-08-12T08:46:14+00:00","dateModified":"2013-12-30T20:51:47+00:00","description":"In this tutorial we are going to see how activation and passivation works in a Stateful Java Enterprise Session Bean. 1. Introduction Stateful Session","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2013\/08\/ejb-passivation-and-activation-example.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2013\/08\/ejb-passivation-and-activation-example.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2013\/08\/ejb-passivation-and-activation-example.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/enterprise-java-logo.jpg","width":150,"height":150,"caption":"java-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2013\/08\/ejb-passivation-and-activation-example.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"EJB passivation and activation example"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/aca65ecdda8de63ce629d2754da61f11","name":"Nikos Maravitsas","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/3969f52bbf541170fe1ae074a6848e1085b8180438db323f626a436a7d19b23f?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/3969f52bbf541170fe1ae074a6848e1085b8180438db323f626a436a7d19b23f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3969f52bbf541170fe1ae074a6848e1085b8180438db323f626a436a7d19b23f?s=96&d=mm&r=g","caption":"Nikos Maravitsas"},"description":"Nikos has graduated from the Department of Informatics and Telecommunications of The National and Kapodistrian University of Athens.","sameAs":["http:\/\/www.javacodegeeks.com\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/nikos-maravitsas"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/16302","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=16302"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/16302\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/112"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=16302"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=16302"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=16302"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}