concurrent
Blocking Queue example to execute commands
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 | import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; private BlockingQueue<Command> workQueue = new LinkedBlockingQueue<Command>(); public void addCommand(Command command) { workQueue.offer(command); } public Object call() throws Exception { try { Command command = workQueue.take(); command.execute(); } catch (InterruptedException e) { throw new WorkException(e); } } |
Related Article:
Reference: Java Concurrency Part 5 – Blocking Queues from our JCG partners at the Carfey Software blog