I have a class that takes objects from a BlockingQueue and processes them by calling take() in a continuous loop. At some point, I know that no objects will be added to the queue. How to abort the take() method so that it locks the lock?
Here is a class that processes objects:
public class MyObjHandler implements Runnable { private final BlockingQueue<MyObj> queue; public class MyObjHandler(BlockingQueue queue) { this.queue = queue; } public void run() { try { while (true) { MyObj obj = queue.take();
And here is the method that this class uses to process objects:
public void testHandler() { BlockingQueue<MyObj> queue = new ArrayBlockingQueue<MyObj>(100); MyObjectHandler handler = new MyObjectHandler(queue); new Thread(handler).start();
java concurrency interrupt blocking
MCS May 01 '09 at 17:24 2009-05-01 17:24
source share