1 Reply Latest reply on Dec 2, 2011 11:04 PM by Christian Sadilek

    concurrency and message/command processing

    Alvin McMurdy Newbie



      The errai bus documentation is a little vague on concurrency issues, but between that and the source code I think I understand what is going on --- can someone tell me if I've got this right?


      For the sake of this discussion, let's say that all the messages are directed to a @Command method "myCommand()" belonging to a @Service class "MyService":


      • With SimpleDispatcher, an incoming message is channeled directly to myCommand() (through the bus). The inbound HTTP POST request will not get a response until myCommand() has executed --- and myCommand() will be executed by the same thread handling the inbound request, hence that thread will be tied up until myCommand() is done.
      • However... even with SimpleDispatcher, since the servlet container may handle multiple concurrent requests via multiple threads, it is possible for myCommand() to be executed concurrently multiple times. So, myCommand() must be thread-safe in that manner.


      On the other hand:


      • With AsyncDispatcher, an incoming message is put immediately into a queue. The inbound HTTP POST request will receive a response as soon as the message is queued, and then the thread handling the request will be free to handle another.
      • Messages are pulled out of the queue --- and thus, myCommand() is executed --- by threads in a worker-pool whose size is controlled by the async_thread_pool_size property.  If the pool_size is 1, then myCommand() is effectively executed in a single-threaded manner and will not have to deal with any concurrency issues --- and it is effectively shielded from any concurrency that the servlet container uses in handling inbound requests.


      Does that sound right?