Multithreading using MDB

Discussions

General J2EE: Multithreading using MDB

  1. Multithreading using MDB (1 messages)

    I have one multithreaded application which used to spawn different processes. This is application is being ported to J2EE environment.

    Initially the plan was to use MDB (Message Driven Beans) to spawn mutliple threads and get the task done. But the main problem with MDB is the communication from the clients again.

    When a message comes, the application server spawns one thread and calls the onMessage(). But the problem I am facing is to send notification from the client to the spawned thread. If another JMS message is send it will be delivered into another thread.

    The threads will remain for some time because it is a long running process. Sometimes these processes should be aborted.

    I don't know how to send notification to a thread (spawned for MDB) to abort the process. Please give me some inputs. Can I use transactions in this context?

    Many thanks,
    Sameer
  2. There is no way you can notify an MDB thread. However normally processing of the JMS messages is not done in MBDs directly. They only retrieve the messages, transform them into a more "readable" for the application form and delegate the actual processing to a session bean (preferably local). If the session bean is statefull, it can implement session synchronization interface and it will be called right before its transaction commits or rollbacks. Within this method you can check a flag raised somewhere in persistance layer and set the transaction to rollback.