Concatenates tasks to one task. After first tasks run is completed,
next start is submitted and so on, until all tasks are run or exception
is thrown.
run is completed.
@param runnables
@return
506020
public Runnable concat(Runnable... runnables)
    {
        if (runnables.length == 0)
        {
            throw new IllegalArgumentException("empty");
        }
        Runnable r = runnables[runnables.length-1];
        for (int ii=runnables.length-2;ii>=0;ii--)
        {
            r = concat(runnables[ii], r);
        }
        return r;
    }
595245
public static void asyncExecute(Runnable runnable) {
		if (runnable != null) {
			try {
				Para.getExecutorService().execute(runnable);
			} catch (RejectedExecutionException ex) {
				logger.warn(ex.getMessage());
				try {
					runnable.run();
				} catch (Exception e) {
					logger.error(null, e);
				}
			}
		}
	}
1003077
public static TimerTask toTimerTask(Runnable runnable)
   {
	if(runnable instanceof TimerTask)
	   return (TimerTask) runnable;
	
	return new TimerTaskRunnerAdapter(runnable);
   }
415247
synchronized List<TaskStatus> getTasksFromRunningJobs() {
    List<TaskStatus> result = new ArrayList<TaskStatus>(tasks.size());
    for (Map.Entry <JobID, RunningJob> item : runningJobs.entrySet()) {
      RunningJob rjob = item.getValue();
      synchronized (rjob) {
        for (TaskInProgress tip : rjob.tasks) {
          result.add(tip.getStatus());
        }
      }
    }
    return result;
  }
453042
private static Runnable nextTask() {
		synchronized (lock) {
			// Block until we have another object in the queue to execute.
			while (taskList.isEmpty()) {
				try {
					lock.wait();
				} catch (InterruptedException ie) {
				}
			}
			return (Runnable) taskList.removeLast();
		}
	}
470767
@GuardedBy("evictionLock")
    void runTasks(Task[] tasks, int maxTaskIndex) {
        for (int i = 0; i <= maxTaskIndex; i++) {
            runTasksInChain(tasks[i]);
        }
    }
472188
public UBench addTask(String name, Runnable task) {
        return putTask(name, () -> {
            long start = System.nanoTime();
            task.run();
            return System.nanoTime() - start;
        });
    }
687049
public void doneOnSubTasksDone() {
		if (jp != null) return;
		synchronized (tasks) {
			jp = new JoinPoint<>();
			for (SubTask task : tasks) jp.addToJoinDoNotCancel(task.getProgress().getSynch());
		}
		jp.listenInline(new Runnable() {
			@Override
			public void run() {
				if (jp.hasError()) error(jp.getError());
				else done();
			}
		});
		jp.start();
	}
510827
def merge_task_lists(runset_results, tasks):
    
    for runset in runset_results:
        # create mapping from id to RunResult object
        # Use reversed list such that the first instance of equal tasks end up in dic
        dic = dict([(run_result.task_id, run_result) for run_result in reversed(runset.results)])
        runset.results = [] # clear and repopulate results
        for task in tasks:
            run_result = dic.get(task)
            if run_result is None:
                logging.info("    No result for task '%s' in '%s'.",
                             task[0], Util.prettylist(runset.attributes['filename']))
                # create an empty dummy element
                run_result = RunResult(task, None, result.CATEGORY_MISSING, None, None,
                                       runset.columns, [None]*len(runset.columns))
            runset.results.append(run_result)
520957
protected <T> RunnableFuture<T> newTaskFor(Runnable runnable, T value) {
        return new ClusteredFutureTask<T>(runnable, value);
    }
1003726
public SequencalJobExecuteResults runAll() {
        SequencalJobExecuteResults results = new SequencalJobExecuteResults();
        for (Job job : jobs) {
            job.setJarByClass(SequencalJobChain.class);
            try {
                boolean isSuccessful = job.waitForCompletion(true);
                results.add(new SequencalJobExecuteResult(isSuccessful, job.getJobName()));
                if (!isSuccessful) {
                    break;
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        return results;
    }
818608
static Runnable composeWithExceptions(Runnable a, Runnable b) {
        return new Runnable() {
            @Override
            public void run() {
                try {
                    a.run();
                }
                catch (Throwable e1) {
                    try {
                        b.run();
                    }
                    catch (Throwable e2) {
                        try {
                            e1.addSuppressed(e2);
                        } catch (Throwable ignore) {}
                    }
                    throw e1;
                }
                b.run();
            }
        };
    }
530039
public synchronized Map<String, List<Integer>> getList() {
    final Map<String, List<Integer>> tasks = new LinkedHashMap<>();

    tasks.put("Running", getTaskIdList(runningTasks));
    tasks.put("Waiting", getTaskIdList(taskQueue));
    tasks.put("Finished", getTaskIdList(finishedTasks));
    tasks.put("Canceled", getTaskIdList(canceledTasks));

    return tasks;
  }
585992
protected Thread newThread(Runnable task) {
    Thread result = new Thread(wrapTask(task));
    result.setDaemon(true);
    return result;
  }
455973
protected boolean runAllTasks() {
        assert inEventLoop();
        boolean fetchedAll;
        boolean ranAtLeastOne = false;

        do {
            fetchedAll = fetchFromScheduledTaskQueue();
            if (runAllTasksFrom(taskQueue)) {
                ranAtLeastOne = true;
            }
        } while (!fetchedAll); // keep on processing until we fetched all scheduled tasks.

        if (ranAtLeastOne) {
            lastExecutionTime = ScheduledFutureTask.nanoTime();
        }
        afterRunningAllTasks();
        return ranAtLeastOne;
    }
120611
public static Action0 fromRunnable(Runnable run, Worker inner) {
        if (run == null) {
            throw new NullPointerException("run");
        }
        return new ActionWrappingRunnable(run, inner);
    }
596812
private Runnable createStopTask() {
    return new Runnable() {
      @Override
      public void run() {
        try {
          // Close the ZK connection in this task will make sure if there is ZK connection created
          // after doStop() was called but before this task has been executed is also closed.
          // It is possible to happen when the following sequence happens:
          //
          // 1. session expired, hence the expired event is triggered
          // 2. The reconnect task executed. With Service.state() == RUNNING, it creates a new ZK client
          // 3. Service.stop() gets called, Service.state() changed to STOPPING
          // 4. The new ZK client created from the reconnect thread update the zooKeeper with the new one
          closeZooKeeper(zooKeeper.getAndSet(null));
          notifyStopped();
        } catch (Exception e) {
          notifyFailed(e);
        }
      }
    };
  }