21import java.util.HashMap;
23import java.util.concurrent.ArrayBlockingQueue;
24import java.util.concurrent.ExecutionException;
25import java.util.concurrent.Future;
26import java.util.concurrent.RejectedExecutionHandler;
27import java.util.concurrent.ThreadPoolExecutor;
28import java.util.concurrent.TimeUnit;
30import javax.swing.JProgressBar;
32import denoptim.programs.combinatorial.FragSpaceExplorer;
33import denoptim.programs.denovo.GARunner;
54 private static ThreadPoolExecutor
tpe;
60 new HashMap<Task,Future<?>>();
96 private static final Object
LOCK =
new Object();
104 TimeUnit.SECONDS,
new ArrayBlockingQueue<Runnable>(
queueSize));
107 tpe.setRejectedExecutionHandler(
new RejectedExecutionHandler()
110 public void rejectedExecution(Runnable r,
111 ThreadPoolExecutor executor)
116 executor.getQueue().put(r);
118 catch (InterruptedException ex)
120 ex.printStackTrace();
126 Runtime.getRuntime().addShutdownHook(
new ShutDownHook());
128 tpe.prestartAllCoreThreads();
145 if (!
tpe.awaitTermination(1, TimeUnit.SECONDS))
150 catch (InterruptedException ie)
155 tpe.getQueue().clear();
160 Thread.currentThread().interrupt();
187 synchronized (
LOCK) {
190 if (max==1 && val==1)
220 synchronized (
LOCK) {
245 String s =
"Approximate queue status:<ul>"
246 +
"<li>Running tasks = " +
tpe.getActiveCount() +
"/"
247 +
tpe.getPoolSize() +
"</li>"
248 +
"<li>Queue Size = " +
tpe.getQueue().size()+
"</li></ul>";
263 tpe.submit(task).get();
272 Future<?> future =
tpe.submit(task);
295 expectation.cancel(
true);
304 return tpe.getActiveCount() > 0;
Shutdown hook that stops all child tasks upon shutdown of JavaVM.
Manager for tasks submitted by the GUI.
static void subtractDoneTask()
static final StaticTaskManager instance
The only, static instance of this class.
static JProgressBar queueStatusBar
Reference to progress bar in GUI.
static final Object LOCK
Synchronisation lock for queue progress bar.
static void submitAndWait(Task task)
Submits a task and waits for completion.
static void subtractDoneTasks(int doneTasksCount)
static void submit(Task task)
static void setLinkToProgressBar(JProgressBar bar)
Adds a reference to the given progress bar.
static void addTodoTasks(int addedTasksCount)
static final int queueSize
Queue size.
static final int maxParallelPrograms
Maximum number of denoptim ProgramTasks that can be run in parallel.
static String getQueueSnapshot()
static void addTodoTask()
static final String PROGRESSBARUPDATE
Property change fired to indicate the need to update progress bar.
static boolean hasActive()
static Map< Task, Future<?> > subToFutureMap
Maps the relation between a task that is submitted and its future handle.
static StaticTaskManager getInstance()
Gets the singleton instance of this class.
static ThreadPoolExecutor tpe
The executor of threads.
static int valProgressBar
Value indicated in the progress bar of the GUI.
static int maxProgressBar
Queue max indicator for progress bar in GUI.
static void stop(Task task)
A task that can throw exceptions.
void setNotify(boolean notify)
void stopTask()
Stop the task if not already completed.