I have 4-5 worker threads processing large message queue. And I also have another piece of code which runs using 2-3 workers. I wanted to block all other workers when large message queue is being processed.
I am using JDK 6, and Jms
EDITED:
Queue process workers never terminated. They blocked on queue when no message. These workers are managed by executor thread pool.If I use read-write lock, one of these workers will get blocked too. Also, if used cyclic barrier then I have to terminate threads in order to relase the blocking second process. Since workers are managed by thread pool, it is not assured that all workers will be busy processing messages.
Let me know,
final ExecutorService executor = getExecutorManager().getExecutor();
for (int i = 0; i < threadPoolSize; i++) {
executor.submit(new MessageWorker(qConn));
}
Following is second module, where i want all workers to be blocked while queue processors worker threads are working.
final ExecutorService executor = getExecutorManager().getExecutor();
for (int i = 0; i < threadPoolSize; i++) {
executor.submit(new DbUpdateWorker());
}
ReadWriteLock
in this case. Have all of the small message processors lock the read lock and the large message queue processor lock for writing. Not quite a good fit though. - Gray