concurrent
Blocking Queue example to execute commands
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