Beispiel #1
0
 private void processTasks(Collection<Task> c) {
   if (c == null) return;
   this.totTask += c.size();
   Set<InvokeThread> runningThread = Collections.synchronizedSet(new HashSet<InvokeThread>());
   for (Task t2 : c) {
     t2.setParallelExecuting(true);
     InvokeThread thread = new InvokeThread(t2, runningThread);
     threadPool.add(thread);
     runningThread.add(thread);
     thread.start();
   }
   while (!runningThread.isEmpty())
     try {
       if (this.isInterrupted()) return;
       Thread.sleep(1);
     } catch (InterruptedException ignore) {
     }
 }
Beispiel #2
0
  private void executeTask(Task t) {
    if (!shouldContinue || t == null) return;
    processTasks(t.getDependTasks());

    HMCLog.log("Executing task: " + t.getInfo());
    for (DoingDoneListener<Task> d : taskListener) d.onDoing(t);
    for (DoingDoneListener<Task> d : t.getTaskListeners()) d.onDoing(t);

    boolean flag = true;
    try {
      t.executeTask();
    } catch (Throwable e) {
      t.setFailReason(e);
      flag = false;
    }
    if (flag) {
      HMCLog.log((t.isAborted() ? "Task aborted: " : "Task finished: ") + t.getInfo());
      for (DoingDoneListener<Task> d : taskListener) d.onDone(t);
      for (DoingDoneListener<Task> d : t.getTaskListeners()) d.onDone(t);
      processTasks(t.getAfterTasks());
    } else {
      HMCLog.err("Task failed: " + t.getInfo(), t.getFailReason());
      for (DoingDoneListener<Task> d : taskListener) d.onFailed(t);
      for (DoingDoneListener<Task> d : t.getTaskListeners()) d.onFailed(t);
    }
  }