All Downloads are FREE. Search and download functionalities are using the official Maven repository.

soot.jimple.infoflow.solver.executors.SetPoolExecutor Maven / Gradle / Ivy

There is a newer version: 2.9.0
Show newest version
package soot.jimple.infoflow.solver.executors;

import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

/**
 * Executor class that ensures that no two equal tasks are in the queue at the
 * same time
 * 
 * @author Steven Arzt
 *
 */
public class SetPoolExecutor extends InterruptableExecutor {
	
	protected Set waiting = Collections.newSetFromMap(new ConcurrentHashMap());
	
	public SetPoolExecutor(int corePoolSize, int maximumPoolSize,
			long keepAliveTime, TimeUnit unit, BlockingQueue workQueue) {
		super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
	}
	
	@Override
	public void execute(Runnable command) {
		// Make sure that we don't schedule a task for execution that is already
		// in the queue
		if (waiting.add(command))
			super.execute(command);
	}
	
	@Override
	protected void afterExecute(Runnable r, Throwable t) {
		waiting.remove(r);
		super.afterExecute(r, t);
	}
	
	@Override
	public void interrupt() {
		super.interrupt();
		this.waiting.clear();
	}
	
	@Override
	public void shutdown() {
		super.shutdown();
		this.waiting.clear();
	}
	
	@Override
	public List shutdownNow() {
		List tasks = super.shutdownNow();
		this.waiting.clear();
		return tasks;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy