Code example for LinkedBlockingDeque

0
	private BlockingDeque<Runnable> taskQueue;
	private ExecutorService exec;
	private volatile Thread	schedulerThread;
 
	public TaskScheduler(int n) {
		taskQueue = new LinkedBlockingDeque<Runnable>(n);
		exec = Executors.newFixedThreadPool(n + 1);
		exec.execute(this);
	} 
 
	public void run() { 
		schedulerThread = Thread.currentThread();
		while (schedulerThread == Thread.currentThread()) {
			try { 
				Runnable r = taskQueue.take();
				exec.execute(r);
			} catch (InterruptedException e) {
				e.printStackTrace();
			} 
		} 
Stop searching for code, let great code find you!  Add Codota to your java IDE