3 Replies Latest reply on Oct 30, 2013 10:27 AM by aqtwrdnr

    How to use a ReentrantLock for the instances of a message-driven bean?

    aqtwrdnr

      I have a message driven bean (of which multiple instances are spawned by JBoss), and one of the instances will eventually detect some special condition on which I want all message driven bean instances to skip any new messages they receive.

       

      I was thinking about using a ReentrantLock when this special condition occurs and check it before processing messages. However, how do I distribute the same ReentrantLock between my MDB instances? I see different solutions, but I do not know which one is preferred:

      1. use a private final static Lock = new ReentrantLock() : final because java ee does not allow non-final static variables.
      2. use an env-entry to define the ReentrantLock and use it in all instances.
      3. Create a SingletonBean which holds the ReentrantLock and retrieve the lock from it in the MDB instances.

       

      What would be the preferred way?

       

      Thanks in advance!

       

      Barry NL