3 Replies Latest reply on Jul 9, 2007 4:37 AM by Carlo de Wolf

    Can SLSB be dirty after new injection?

    Gena Newbie

      Hello
      just one stupid question. I invoke 3 method on one injected stateless bean instance. During the invocation chain this SLSB holds the internal state. After the the work is done, i forget this SLSB.

      And now the question, if i repeat the operation described above in the next converational step (web request) can i receive a dirty SLSB injected from the contaner?

      I hope no, but if its possible to make a SLSB dirty for the container (and all user), how can i remove this bean from the pool instead of cleaning it up?

      Thanks, Gena

        • 1. Re: Can SLSB be dirty after new injection?
          Carlo de Wolf Master

          Yes, a stateless session bean is kept in a method-ready pool. So each instance is reused.

          To invalidate a stateless session bean throw a RuntimeException that has not been marked as an application exception from a business method. (EJB 3 Core 4.5.3)

          • 2. Re: Can SLSB be dirty after new injection?
            Gena Newbie

            @wolfc thank you for the answer!

            its a pity, that a small error (misunderstanding of this aspect of ejb-spec) results in a total instability of a whole application. I think, its really confusing, to get a dirty new injected STATELESS bean from a container.

            Couldn't it be better, to purge the dirty SLSB and from some threshold to fill the pool with new instances?

            Are there some important reason why the SLSBs aren't one way? Is it really so expensive, to create asynchronously thousands of whole instances of a bean and put them on demand to the method-ready pool?


            Isn't the throwing an exception an expensive way to remove the dirty instance?

            Thank you and excuse my nosiness!

            Gena


            • 3. Re: Can SLSB be dirty after new injection?
              Carlo de Wolf Master

               

              "gena777" wrote:
              Couldn't it be better, to purge the dirty SLSB and from some threshold to fill the pool with new instances?

              You can create your own interceptor which determines if you use a new instance and when to discard it. See http://viewvc.jboss.org/cgi-bin/viewvc.cgi/jbossas/trunk/ejb3/src/main/org/jboss/ejb3/stateless/StatelessInstanceInterceptor.java?view=markup

              "gena777" wrote:
              Are there some important reason why the SLSBs aren't one way? Is it really so expensive, to create asynchronously thousands of whole instances of a bean and put them on demand to the method-ready pool?

              Yes and yes. Injection can become quit heavy. But each application is different, you'll have to benchmark when you got your new interceptor up and running.

              "gena777" wrote:
              Isn't the throwing an exception an expensive way to remove the dirty instance?

              Yes, if you want open a new feature issue in JIRA. An extension of SessionContext with a setDiscard method might be the solution.