Code example for ReentrantLock

Methods: newCondition

0
package net.behoo.appmarket.http; 
 
import java.util.concurrent.ScheduledThreadPoolExecutor; 
import java.util.concurrent.locks.Condition; 
import java.util.concurrent.locks.ReentrantLock; 
 
public class PausableThreadPoolExecutor extends ScheduledThreadPoolExecutor {
	private boolean isPaused = false;
	private ReentrantLock pauseLock = new ReentrantLock();
	private Condition unpaused = pauseLock.newCondition();
	    
	public PausableThreadPoolExecutor(int corePoolSize) {
		super(corePoolSize);
	} 
 
	protected void beforeExecute(Thread t, Runnable r) {
		super.beforeExecute(t, r);
		pauseLock.lock();
		try { 
			while (isPaused) unpaused.await();
		} catch (InterruptedException ie) {
			t.interrupt();
		} finally { 
			pauseLock.unlock();