1 Reply Latest reply on Mar 30, 2014 11:02 PM by Kylin Soong

    What is the correct way to use JMSTaskClientConnector(JMSTaskClientConnector is not thread-safe)?

    Kylin Soong Novice

      Can we create JMSTaskClientConnector as singleton, then used by multiple threads concurrently?

       

      JMSTaskClientConnector is not thread-safe, JMSTaskClientConnector use a object scope argument "selector":

      public class JMSTaskClientConnector implements TaskClientConnector { 
      ... 
      private String selector; 
      ... 
      public void write(Object object) { 
              try { 
                  ObjectMessage message = this.producerSession.createObjectMessage(); 
                  this.selector = UUID.randomUUID().toString(); 
      ... 
                  Thread responseThread = new Thread(new Responder(selector, removeEvent)); 
                  responseThread.start(); 
      message.setStringProperty(TaskServiceConstants.SELECTOR_NAME, this.selector);
      

       

      If JMSTaskClientConnector is a singleton used by lots of concurrent thread, the "selector" used by message(send to task queue) and the "selector" in responseThread(handle message from response queue) may different.

       

      What's the correct way to use JMSTaskClientConnector? Does JMSTaskClientConnector be open/close per thread?

        • 1. Re: What is the correct way to use JMSTaskClientConnector(JMSTaskClientConnector is not thread-safe)?
          Kylin Soong Novice

          I have done a great investigation, so I would answer my question myself.

           

          • We don't recommend to use JMS for transporting of Async Human Task in jBPM 5.x, HornetQ is the default and only one supported/well-QA transport, Apache Mina/JMS are experimental options.
          • If use JMS, JMSTaskClientConnector should create/connect/disconnect per request. These because JMS session objects are single threaded and can only be used by single thread that created them. An attempt to use them from another thread would result in an exception or some very strange errors. This is as per JMS specifications.