3 Replies Latest reply on Jun 23, 2009 5:36 AM by newman79

    EJB Web Service Stateful?

    shaikbash

      Hi,
      I have developed a simple EJB based web-service as shown below:

      @Stateless
      @Remote(MySession.class)
      @WebService(endpointInterface = "test.MySession")
      @WebContext(contextRoot = "/mySession")
      public class MySessionBean implements MySession
      {
      private int count;

      public int getCount()
      {
      return ++count;
      }
      }

      This is deployed on JBOSS 4.2.2 server.
      I have a servlet based client, which connects to this service using the jbossws-3.0.1-native-2.0.4 jars. Whenever I call the getCount() method from the client I get an incremented value. I was expecting to always get 1 as the return value, since my EJB is stateless. My question is how is it retaining the state? Any light on this is greately appreciated.

        • 1. Re: EJB Web Service Stateful?
          gcoleman

          Stateless EJBs are only stateless in the sense that they're not associated with any particular client session.

          The actual EJB instances can and will be pooled by the application server.

          • 2. Re: EJB Web Service Stateful?
            shaikbash

            Thanks for the reply.

            • 3. Re: EJB Web Service Stateful?

              Hi all,

              I'm a little new with JbossWS, so maybe the answer is trivial ...

              My web service seems to be stateless : does it mean that an object of my endpoint class is instanciated at each request ?

              But I'd like to create a webservice that keep some objects for all its life (like count in shaikbash's example).

              Does anyone know
              how can I correctly prevent instanciation of my endpoint class at each request and keep the same since start deplyment to undeployment ?