A helper method that executes a task in a worker thread and displays feedback
in a progress windows.

@param strNotice The text notice to display in the ProgressWindow.
@param task      The task to execute in a separate (worker) thread.
190885
public static ProgressFeedback runWithProgress( final String strNotice, final IRunnableWithProgress task )
  {
    return runWithProgress( strNotice, task, false, false );
  }
945534
private void executeTaskAsync() {
        final String taskId = currentTask.getId();

        ListenableFuture<?> future = taskExecutorService.submit(currentTask);
        pendingTasks.put(taskId, future);

        future.addListener(new Runnable() {
            @Override
            public void run() {
                pendingTasks.remove(taskId);
            }
        }, MoreExecutors.sameThreadExecutor());

        hasCurrentTask = false;
    }
1095755
protected void reportWorked(int workIncrement, int currentUnitIndex) {
        if (this.progress != null) {
            if (this.progress.isCanceled()) {
                // Only AbortCompilation can stop the compiler cleanly.
                // We check cancellation again following the call to compile.
                throw new AbortCompilation(true, null);
            }
            this.progress.worked(workIncrement, (this.totalUnits* this.remainingIterations) - currentUnitIndex - 1);
        }
    }
677918
protected void transmitPartialTask(final Task<Diff> result)
		throws TimeoutException
	{

		this.diffedSize += result.byteSize();
		this.processingTimeDiff += System.currentTimeMillis() - startTime;

		super.transmitPartialTask(result);

		startTime = System.currentTimeMillis();
	}
703536
public void executeInIoThread(Runnable task, boolean alwaysAsync) {
        if (!alwaysAsync && isIoThread()) {
            task.run();
        } else {
            registerTask(task);
        }
    }
19077
public void init(JavacTask task, String[] args, boolean addTaskListener) {
        env = new Env();
        for (int i = 0; i < args.length; i++) {
            String arg = args[i];
            if (arg.equals(XMSGS_OPTION)) {
                env.messages.setOptions(null);
            } else if (arg.startsWith(XMSGS_CUSTOM_PREFIX)) {
                env.messages.setOptions(arg.substring(arg.indexOf(":") + 1));
            } else if (arg.matches(XIMPLICIT_HEADERS + "[1-6]")) {
                char ch = arg.charAt(arg.length() - 1);
                env.setImplicitHeaders(Character.digit(ch, 10));
            } else if (arg.startsWith(XCUSTOM_TAGS_PREFIX)) {
                env.setCustomTags(arg.substring(arg.indexOf(":") + 1));
            } else
                throw new IllegalArgumentException(arg);
        }
        env.init(task);

        checker = new Checker(env);

        if (addTaskListener) {
            final DeclScanner ds = new DeclScanner() {
                @Override
                void visitDecl(Tree tree, Name name) {
                    TreePath p = getCurrentPath();
                    DocCommentTree dc = env.trees.getDocCommentTree(p);

                    checker.scan(dc, p);
                }
            };

            TaskListener tl = new TaskListener() {
                @Override
                public void started(TaskEvent e) {
                    switch (e.getKind()) {
                        case ANALYZE:
                            CompilationUnitTree tree;
                            while ((tree = todo.poll()) != null)
                                ds.scan(tree, null);
                            break;
                    }
                }

                @Override
                public void finished(TaskEvent e) {
                    switch (e.getKind()) {
                        case PARSE:
                            todo.add(e.getCompilationUnit());
                            break;
                    }
                }

                Queue<CompilationUnitTree> todo = new LinkedList<CompilationUnitTree>();
            };

            task.addTaskListener(tl);
        }
    }
6924
@Override
    public void execute(Runnable task) {
        Executor executor = getScheduledExecutor();
        try {
            executor.execute(errorHandlingTask(task, false));
        } catch (RejectedExecutionException ex) {
            throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex);
        }
    }
1255500
function(task) {
  task.error = false;
  task.state = sStateTable[task.state][START];
  setTimeout(function() {
    if(task.state === RUNNING) {
      task.swapTime = +new Date();
      task.run(task);
      runNext(task, 0);
    }
  }, 0);
}
109461
private void executeTasklet(final ExecutorService commandExecutor,
                              final ConcurrentMap<Integer, Future> futures,
                              final MasterToWorkerRequest masterToWorkerRequest) {
    final CountDownLatch latch = new CountDownLatch(1);
    final TaskletExecutionRequest taskletExecutionRequest = (TaskletExecutionRequest) masterToWorkerRequest;

    // Scheduler Thread: Pass the command to the worker thread pool to be executed
    // Record future to support cancellation.
    futures.put(
        taskletExecutionRequest.getTaskletId(),
        commandExecutor.submit(new Runnable() {
          @Override
          public void run() {
            final WorkerToMasterReports reports;
            final List<WorkerToMasterReport> holder = new ArrayList<>();

            try {
              // Command Executor: Execute the command
              final WorkerToMasterReport workerToMasterReport =
                  new TaskletResultReport(taskletExecutionRequest.getTaskletId(), taskletExecutionRequest.execute());
              holder.add(workerToMasterReport);
            } catch (final InterruptedException ex) {
              // Assumes that user's thread follows convention that cancelled Futures
              // should throw InterruptedException.
              final WorkerToMasterReport workerToMasterReport =
                  new TaskletCancelledReport(taskletExecutionRequest.getTaskletId());
              LOG.log(Level.WARNING, "Tasklet with ID {0} has been cancelled", taskletExecutionRequest.getTaskletId());
              holder.add(workerToMasterReport);
            } catch (Exception e) {
              // Command Executor: Tasklet throws an exception
              final WorkerToMasterReport workerToMasterReport =
                  new TaskletFailureReport(taskletExecutionRequest.getTaskletId(), e);
              holder.add(workerToMasterReport);
            }

            reports = new WorkerToMasterReports(holder);
            workerReports.addLast(kryoUtils.serialize(reports));
            try {
              latch.await();
            } catch (final InterruptedException e) {
              LOG.log(Level.SEVERE, "Cannot wait for Future to be put.");
              throw new RuntimeException(e);
            }
            futures.remove(taskletExecutionRequest.getTaskletId());
            heartBeatTriggerManager.triggerHeartBeat();
          }
        }));

    // Signal that future is put.
    latch.countDown();
  }
446347
public void writeRevision(final Task<Revision> task)
		throws IOException
	{

		if (task.getTaskType() == TaskTypes.TASK_PARTIAL_FIRST
				|| task.getTaskType() == TaskTypes.TASK_FULL) {

			this.writer.write(WikipediaXMLKeys.KEY_START_PAGE.getKeyword()
					+ "\r\n");

			ArticleInformation header = task.getHeader();

			this.writer.write("\t"
					+ WikipediaXMLKeys.KEY_START_TITLE.getKeyword());
			this.writer.write(header.getArticleName());
			this.writer.write(WikipediaXMLKeys.KEY_END_TITLE.getKeyword()
					+ "\r\n");

			this.writer
					.write("\t" + WikipediaXMLKeys.KEY_START_ID.getKeyword());
			this.writer.write(Integer.toString(header.getArticleId()));
			this.writer
					.write(WikipediaXMLKeys.KEY_END_ID.getKeyword() + "\r\n");
		}

		Revision rev;
		Iterator<Revision> revIt = task.iterator();
		while (revIt.hasNext()) {

			this.writer
					.write("\t"
							+ WikipediaXMLKeys.KEY_START_REVISION.getKeyword()
							+ "\r\n");
			rev = revIt.next();

			this.writer.write("\t\t"
					+ WikipediaXMLKeys.KEY_START_ID.getKeyword());
			this.writer.write(Integer.toString(rev.getRevisionID()));
			this.writer
					.write(WikipediaXMLKeys.KEY_END_ID.getKeyword() + "\r\n");

			this.writer.write("\t\t<revCount>");
			this.writer.write(Integer.toString(rev.getRevisionCounter()));
			this.writer.write("</revCount>\r\n");

			this.writer.write("\t\t"
					+ WikipediaXMLKeys.KEY_START_TIMESTAMP.getKeyword());
			this.writer.write(rev.getTimeStamp().toString());
			this.writer.write(WikipediaXMLKeys.KEY_END_TIMESTAMP.getKeyword()
					+ "\r\n");

			this.writer.write("\t\t"
					+ WikipediaXMLKeys.KEY_START_CONTRIBUTOR.getKeyword());
			if(rev.contributorIsRegistered()){
				this.writer.write("\t\t"
						+ WikipediaXMLKeys.KEY_START_USERNAME.getKeyword());
				this.writer.write(rev.getContributorName());
				this.writer.write(WikipediaXMLKeys.KEY_END_USERNAME.getKeyword()
						+ "\r\n");

				this.writer.write("\t\t"
						+ WikipediaXMLKeys.KEY_START_ID.getKeyword());
				this.writer.write(rev.getContributorId());
				this.writer.write(WikipediaXMLKeys.KEY_END_ID.getKeyword()
						+ "\r\n");
			}
			else{
				this.writer.write("\t\t"
						+ WikipediaXMLKeys.KEY_START_IP.getKeyword());
				this.writer.write(rev.getContributorName());
				this.writer.write(WikipediaXMLKeys.KEY_END_IP.getKeyword()
						+ "\r\n");
			}

			this.writer.write(WikipediaXMLKeys.KEY_END_CONTRIBUTOR.getKeyword()
					+ "\r\n");

			if(rev.isMinor()){
				this.writer.write("\t\t"+WikipediaXMLKeys.KEY_MINOR_FLAG.getKeyword()
						+ "\r\n");
			}

			this.writer.write("\t\t"
					+ WikipediaXMLKeys.KEY_START_COMMENT.getKeyword());
			this.writer.write(rev.getComment());
			this.writer.write(WikipediaXMLKeys.KEY_END_COMMENT.getKeyword()
					+ "\r\n");




			this.writer.write("\t\t"
					+ WikipediaXMLKeys.KEY_START_TEXT.getKeyword());
			if (rev.getRevisionText() != null) {
				this.writer.write(rev.getRevisionText());
			}
			this.writer.write(WikipediaXMLKeys.KEY_END_TEXT.getKeyword()
					+ "\r\n");

			this.writer.write("\t"
					+ WikipediaXMLKeys.KEY_END_REVISION.getKeyword() + "\r\n");
		}

		if (task.getTaskType() == TaskTypes.TASK_PARTIAL_LAST
				|| task.getTaskType() == TaskTypes.TASK_FULL) {

			this.writer.write(WikipediaXMLKeys.KEY_END_PAGE.getKeyword()
					+ "\r\n");
		}
		this.writer.flush();
	}
528880
function(task) {
    this.capability = task.capability;
    this.specs = task.specs;
    this.process = child.fork(
      __dirname + '/runFromLauncher.js',
      process.argv.slice(2), {
        cwd: process.cwd(),
        silent: true
      }
    );
    this.reporter = reporter.addTaskReporter(task, this.process.pid);
  }
486186
private Runnable decorateTask(Runnable task, boolean isRepeatingTask) {
        Runnable result = TaskUtils.decorateTaskWithErrorHandler(task, this.errorHandler, isRepeatingTask);
        if (this.enterpriseConcurrentScheduler) {
            result = ManagedTaskBuilder.buildManagedTask(result, task.toString());
        }
        return result;
    }
118122
void handlerProcessTask(Task task) {
		assertDispatcherThread();
		
		SerialTaskQueue taskQueue = mQueuesMap.get(task.subscriberCallback.queue);
		if (taskQueue == null) {
			taskQueue = new SerialTaskQueue(task.subscriberCallback.queue);
			mQueuesMap.put(task.subscriberCallback.queue, taskQueue);
			mQueuesList.add(taskQueue);
		}
		taskQueue.offer(task);

		processNextTask();
	}
363133
private void bindProgressBar(final ServiceTaskBase<?> task, final ProgressBar progressBar) {

        // Perform this binding into the JAT to respect widget and task API
        JRebirth.runIntoJAT("Bind ProgressBar to " + task.getServiceHandlerName(),
                            () -> {
                                // Avoid the progress bar to display 100% at start up
                                task.updateProgress(0, 0);
                                // Bind the progress bar
                                progressBar.progressProperty().bind(task.workDoneProperty().divide(task.totalWorkProperty()));
                            });

    }
33258
private void taskComplete(
      HttpRemoteTaskRunnerWorkItem taskRunnerWorkItem,
      WorkerHolder workerHolder,
      TaskStatus taskStatus
  )
  {
    Preconditions.checkState(!Thread.holdsLock(statusLock), "Current thread must not hold statusLock.");
    Preconditions.checkNotNull(taskRunnerWorkItem, "taskRunnerWorkItem");
    Preconditions.checkNotNull(taskStatus, "taskStatus");
    if (workerHolder != null) {
      log.info(
          "Worker[%s] completed task[%s] with status[%s]",
          workerHolder.getWorker().getHost(),
          taskStatus.getId(),
          taskStatus.getStatusCode()
      );
      // Worker is done with this task
      workerHolder.setLastCompletedTaskTime(DateTimes.nowUtc());
    }

    // Notify interested parties
    taskRunnerWorkItem.setResult(taskStatus);
    TaskRunnerUtils.notifyStatusChanged(listeners, taskStatus.getId(), taskStatus);

    // Update success/failure counters, Blacklist node if there are too many failures.
    if (workerHolder != null) {
      blacklistWorkerIfNeeded(taskStatus, workerHolder);
    }

    synchronized (statusLock) {
      statusLock.notifyAll();
    }
  }
565295
void afterWrite(Runnable task) {
        writeBuffer.add(task);
        drainStatus.lazySet(REQUIRED);
        tryToDrainBuffers();
        notifyListener();
    }
133297
@MainThread
    private void handleTaskFinished(Task task) {
        if (task.method.type != EventMethod.Type.SUBSCRIBE) {
            // We are not interested in finished callbacks, only finished subscriber calls
            return;
        }

        if (task.method.isSingleThread) {
            Utils.log(task, "Single-thread method is no longer in use");
            task.method.isInUse = false;
        }

        Event event = task.event;

        if (!activeEvents.contains(event)) {
            Utils.logE(event.getKey(), "Cannot finish already finished event");
            return;
        }

        ((EventBase) event).handlersCount--;

        if (((EventBase) event).handlersCount == 0) {
            // No more running handlers
            activeEvents.remove(event);
            scheduleStatusUpdates(event, EventStatus.FINISHED);
            executeTasks(false);
        }
    }