2 Replies Latest reply on Jan 25, 2007 5:38 PM by Brad O'Hearne

    JbpmThreadServlet and member threads

    Brad O'Hearne Newbie

      I was just looking at the JbpmThreadServlet source code (3.1.2), and noticed that there are two threads started by an instance of this class, and are stored as member variables:

      CommandExecutorThread commandExecutorThread = null;
      SchedulerThread schedulerThread = null;
      ...
      public void init() throws ServletException {
      ...
       commandExecutorThread = new CommandExecutorThread(jbpmConfiguration);
       commandExecutorThread.start();
      
       schedulerThread = new SchedulerThread(jbpmConfiguration);
       schedulerThread.start();
      }


      Now, correct me if I'm wrong, but although the SingleThreadModel servlet was dropped in newer Servlet specs (2.2 & newer or close as I recall) I believe that management of servlet instances isn't specified by the servlet spec, no? While I cannot necessarily name you a particular servlet engine that manages servlets through pooling vs. a single servlet instance (because I use almost exclusively Tomcat or embedded Tomcat in JBoss), I can imagine scenarios where you might want to. I believe that it is entirely legal according to the spec for a servlet engine implementer to have more than one instance of a servlet class in existence at the same time. As a result, wouldn't this implementation of the schedulerThread and commandExecutorThread be problematic, as they are tied to instances of this Servlet class, rather than tied as statics to the class itself? You'd have multiple SchedulerThreads and CommandExecutorThreads running at the same time, no?

      Thanks,

      Brad

        • 1. Re: JbpmThreadServlet and member threads
          Alejandro Guizar Master

          You're right, a container is free to instantiate a servlet class multiple times as it sees fit.

          Recently, a customer proposed us to reimplement the JbpmThreadsServlet as a servlet context listener, which is guaranteed to execute only once. I filed the request as JBPM-742, but haven't found the time to implement it yet.

          For backwards compatibility, static variables are not the right choice because you could have thread servlets in several web modules. The servlet context comes in handy here.

          • 2. Re: JbpmThreadServlet and member threads
            Brad O'Hearne Newbie

            Alex,

            Thanks for the reply. Yeah, it would seem that the ServletContextListener would probably be the logical way to implement it. Seems simple enough -- in fact, I'll probably have to do that for my application anyway.

            Brad