session timeout

Discussions

EJB design: session timeout

  1. session timeout (8 messages)

    I have written a smiple statefull bean that counts up,

    i have this code in my jsp page [client]

    <%@page contentType="text/html"%>
    <html>
    <head><title>JSP Page</title></head>
    <body>
    <%@ page import="javax.rmi.*, javax.ejb.*, javax.naming.*, examples.*" %>
    <%!
        private Count count;
        public void jspInit() {
             try {
                InitialContext c = new InitialContext();
                Object obj = c.lookup("java:comp/env/Count");
                CountHome home = (CountHome)PortableRemoteObject.narrow(obj, CountHome.class);
                count = home.create(1);
             } catch (Exception ex) {
                    System.out.println("Unable to lookup home: "+ "ThePerson "+ ex.getMessage());
             }
        }
    %>
    <%
       
         out.println(count.count());
          
    %>

    </body>
    </html>

    when i refresh the jsp page , the bean counts up, but if i leave my container for about 20 minutes, and then refresh the page again , i got an exception in container console

    NoSuchObjectException: session has timed out

    can anyone explain this for me ?

    -Thanx

    Threaded Messages (8)

  2. session timeout[ Go to top ]

    Is is possible that the JSP never gets unloaded, so after 20 minutes the jspInit() method is not re-executed, but the bean has timed out?
  3. session timeout[ Go to top ]

    I know that jspInit() runs just once, but I want to know why container call ejbRemove() after a while ?
  4. session timeout[ Go to top ]

    I guess that was my point. The EJB spec says that the container can move the Bean to the Does Not Exist state after a timeout without calling the ejbRemove().

    Taken from the Oriely "Enterprise Java Beans 3rd Edition"

    "The container can also move the bean instance from the Method-Ready state to the Does Not Exist state if the bean times out. ... When a timeout occurs in the Method-Ready state, the container may, but is not required to, call the ejbRemove() method. ..."
  5. session timeout[ Go to top ]

    I get the point.
    now i want to know is there a way to specify the timeout for container ? [like HttpSession ]
  6. session timeout[ Go to top ]

    Yeah, in the deployment descriptor of the EJB. But I'd be careful playing with that. Are you trying to solve a particular business problem or just prototyping something?
  7. session timeout[ Go to top ]

    now i want to know is there a way to specify the timeout for container ? [like HttpSession ]


    You have to look carefully at your EJB container specific documentation. Most of app. servers I know do statefull session EJB timeout in server specific configuration part.
  8. session timeout[ Go to top ]

    I use oc4j.
    suppose that i want to write a shopping card, before this i have written a shopping card using HttpSession, I want to know how i can write it using stateful session bean, and how can i deal with session timeout ?

    --Thanx
  9. session timeout[ Go to top ]

    I use oc4j.

    > suppose that i want to write a shopping card, before this i have written a shopping card using HttpSession, I want to know how i can write it using stateful session bean, and how can i deal with session timeout ?
    >
    > --Thanx

    What you really want is HttpSession to last as long as your SFSB. (Eg. OC4J container in your case not to perform ejbRemove() on your session bean as long as HttpSession is valid.) I think it is logical why life of the session bean has not been defined in the specification.

    OC4J and Orion define container specific settings in orion-ejb-jar.xml and for details have a look at www.orionserver.com and otn.oracle.com .

    Cheers,
    Drazen
    LABeCom - Laboratory for Enhanced Computing Machinery