1 Reply Latest reply on Oct 9, 2011 3:12 AM by salaboy21

    reuse StatefulKnowledgeSession, is StatefulKnowledgeSession lightweight

    missedone

      hi, folks

       

      i'm using jBPM5 and here is question about how to effectively use the StatefulKnowledgeSession.

       

      is StatefulKnowledgeSession lightweight?

       

      is there any potential risk if we implement the strategy that create StatefulKnowledgeSession for each request, that means, create StatefulKnowledgeSession when every time call startProcess, and dispose it after the process instance complete.

       

      I read the javadoc of StatefulKnowledgeSession, it clear state that: "

      After the application finishes using the session, though, it must call the dispose() method in order to free the resources and used memory.

      "

       

      at this monment, what i can image is that, if there are lots of active process instance not complete, that will cause lots of StatefulKnowledgeSession resources not released, which could be potential memory leak? is this correct?

       

      do you guys have any best practice or pattern of useing StatefulKnowledgeSession? for example, options like:

      reuse single StatefulKnowledgeSession?

      reuse StatefulKnowledgeSession in a pool?

      oneStatefulKnowledgeSession per request?

       

      Thanks

        • 1. Re: reuse StatefulKnowledgeSession, is StatefulKnowledgeSession lightweight
          salaboy21

          Hi Nick,

          Your question is extremely related with your architecture and your goals. Drools and jBPM5 are flexible enough to let you decide how many sessions do you want to have and how to handle them. If you want to start a business process per request and you have long running processes (that means that you will need to configure persistence) you can have one session per process instance. As you mention creating a knowledge session is cheap enough to do it per request, but you need to analyze how many request are you getting in your application and what's the scope of the business process. Most of the time if your process solve a business situation you will not have troubles with creating one session per request, becase at business level it is not common to recieve too many business request together.

          About calling the dispose() method, you need to do that every time that your process reaches a wait state if you are using persistence, to make sure that you free up all the resources and anoher thread will reload the session from the DB with a coherent status.

           

          Cheers