If {@link #pending} is non-null (meaning someone requested the task to be kicked),
but {@link #inprogress} is null (meaning none is executing right now),
get one going.
335652
private synchronized void maybeRun() {
        if (inprogress==null && pending!=null) {
            base.submit(new Callable<Void>() {
                @Override
                public Void call() throws Exception {
                    synchronized (AtmostOneTaskExecutor.this) {
                        // everyone who submits after this should form a next batch
                        inprogress = pending;
                        pending = null;
                    }

                    try {
                        inprogress.set(task.call());
                    } catch (Throwable t) {
                        LOGGER.log(Level.WARNING, null, t);
                        inprogress.setException(t);
                    } finally {
                        synchronized (AtmostOneTaskExecutor.this) {
                            // if next one is pending, get that scheduled
                            inprogress = null;
                            maybeRun();
                        }
                    }
                    return null;
                }
            });
        }
    }
257838
private boolean taskShouldExecute(Task task, TaskRecord taskRecord) {
        String taskID = taskRecord.getTaskID();
        if (taskRecord.getStatus() == TaskStatus.NEVER_EXECUTED) {
            m_logger.debug("Task '{}' has never executed", taskID);
            return true;
        }
        if (taskRecord.getStatus() == TaskStatus.IN_PROGRESS) {
            m_logger.debug("Task '{}' is already being executed", taskID);
            return false;
        }
        
        Calendar startTime = taskRecord.getTime(TaskRecord.PROP_START_TIME);
        long startTimeMillis = startTime == null ? 0 : startTime.getTimeInMillis();
        long taskPeriodMillis = task.getTaskFreq().getValueInMinutes() * 60 * 1000;
        long nowMillis = System.currentTimeMillis();
        boolean bShouldStart = startTimeMillis + taskPeriodMillis <= nowMillis;
        m_logger.debug("Considering task {}: Last started at {}; periodicity in millis: {}; current time: {}; next start: {}; should start: {}",
                      new Object[]{task.getTaskID(),
                                   Utils.formatDateUTC(startTimeMillis, Calendar.MILLISECOND),
                                   taskPeriodMillis,
                                   Utils.formatDateUTC(nowMillis, Calendar.MILLISECOND),
                                   Utils.formatDateUTC(startTimeMillis + taskPeriodMillis, Calendar.MILLISECOND),
                                   bShouldStart});
        return bShouldStart;
    }
807471
function invokePending(kind, data) {
      var xs = pending
      pending.length = 0
      for (var i = 0; i < xs.length; ++i)  xs[i][kind](value) }
116101
def pop_pending_if_empty(self, element):
        """"""
        actions = self.state[self.state['current_step']]['actions']
        elem = self.current_target().tree
        if actions[-1][0] == ('target') and actions[-1][1].tree == elem:
            actions.pop()
            actions.pop()
            actions.pop()
1007606
def has_pending(self):
        
        if self.workqueue:
            return True

        for assigned_unit in self.assigned_work.values():
            if self._pending_of(assigned_unit) > 0:
                return True

        return False
469710
public boolean isInProgress(RequestCycle cycle)
	{
		Boolean inProgress = cycle.getMetaData(IN_PROGRESS_KEY);
		return inProgress!=null?inProgress:false;
	}
733033
public synchronized T getNonBlocking ()
    {
        if (_count == 0) {
            return null;
        }

        // pull the object off, and clear our reference to it
        T retval = _items[_start];
        _items[_start] = null;

        _start = (_start + 1) % _size;
        _count--;

        return retval;
    }
303268
@Override
  public void send(T value, Result<Void> result)
  {
    /*
    if (! init() && pendingSend(value, result)) {
      return;
    }
    */
    
    send(value);

    result.ok(null);
  }
313435
private void awaitTasks() {
        if (_tasksPending.get() == 0) {
            return;
        }
        synchronized (this) {
            while (_tasksPending.get() != 0) {
                try {
                    logger.info("Scan tasks still pending, waiting");
                    wait();
                } catch (final InterruptedException e) {
                    logger.debug("Interrupted while awaiting task completion", e);
                }
            }
        }
    }
883788
synchronized TaskInProgress findTaskToKill(List<TaskAttemptID> tasksToExclude) {
    TaskInProgress killMe = null;
    for (Iterator it = runningTasks.values().iterator(); it.hasNext();) {
      TaskInProgress tip = (TaskInProgress) it.next();

      if (tasksToExclude != null
          && tasksToExclude.contains(tip.getTask().getTaskID())) {
        // exclude this task
        continue;
      }

      if ((tip.getRunState() == TaskStatus.State.RUNNING ||
           tip.getRunState() == TaskStatus.State.COMMIT_PENDING) &&
          !tip.wasKilled) {

        if (killMe == null) {
          killMe = tip;

        } else if (!tip.getTask().isMapTask()) {
          //reduce task, give priority
          if (killMe.getTask().isMapTask() ||
              (tip.getTask().getProgress().get() <
               killMe.getTask().getProgress().get())) {

            killMe = tip;
          }

        } else if (killMe.getTask().isMapTask() &&
                   tip.getTask().getProgress().get() <
                   killMe.getTask().getProgress().get()) {
          //map task, only add if the progress is lower

          killMe = tip;
        }
      }
    }
    return killMe;
  }
859360
private void onNextAttemptStarted(CompletionStage<Boolean> futureOutcome) {
    assert executor.inEventLoop();
    state = State.ATTEMPT_IN_PROGRESS;
    futureOutcome
        .whenCompleteAsync(this::onNextAttemptCompleted, executor)
        .exceptionally(UncaughtExceptions::log);
  }
742203
public void startPriority(Runnable task)
  {
    ClassLoader loader = Thread.currentThread().getContextClassLoader();

    // long expire = CurrentTime.getCurrentTimeActual() + PRIORITY_TIMEOUT;
    long expire = MAX_EXPIRE;

    boolean isPriority = true;
    boolean isQueue = true;
    boolean isWake = true;

    if (! scheduleImpl(task, loader, expire, isPriority, isQueue, isWake)) {
      String msg = (this + " unable to start priority thread " + task
                    + " pri-min=" + getPriorityIdleMin()
                    + " thread=" + getThreadCount()
                    + " idle=" + getThreadIdleCount()
                    // + " pri-idle=" + getPriorityIdleCount()
                    + " starting=" + getThreadStartingCount()
                    + " max=" + getThreadMax());

      log.warning(msg);

      HealthSystemFacade.fireEvent(THREAD_FULL_EVENT, msg);

      OverflowThread item = new OverflowThread(task);
      item.start();
    }
  }
259004
def _has_no_pendings(self, statuses):
        
        return all(s != ClientBatchStatus.PENDING for s in statuses.values())
638278
private void onProgress(final int workerNumber, final int workerSize, final List<Long> pointerList, final float progress) {

		if (progressCache == null) {
			progressCache = new ProgressCache(workerSize, (onRealtimeResultListener != null));
		}

		progressCache.setProgress(workerNumber, progress, pointerList);

		if (onProgressListener != null) {
			onProgressListener.onProgress(progressCache.getProgress());
		}

		if (onRealtimeResultListener != null) {
			onRealtimeResultListener.onRealtimeResultListener(progressCache.getProgress(), progressCache.getResultPointers());
		}
	}
678615
void drain() {
        lock.lock();
        try {
            LOG.finest("Waiting while draining...");
            while (isWorking()
                    && (emptyRequestFuture == null
                    || emptyRequestFuture.isDone())) {
                try {
                    drained.await();
                } catch (InterruptedException intx) {
                    LOG.log(Level.FINEST, INTERRUPTED, intx);
                }
            }
            LOG.finest("Drained");
        } finally {
            lock.unlock();
        }
    }
347830
private void doPreemptionNow() {
    int totalShare = nodeManager.getAllocatedCpuForType(type);
    poolGroupManager.distributeShare(totalShare);
    for (PoolGroupSchedulable poolGroup : poolGroupManager.getPoolGroups()) {
      poolGroup.distributeShare();
    }
    int tasksToPreempt = countTasksShouldPreempt();
    if (tasksToPreempt > 0) {
      LOG.info("Found " + tasksToPreempt + " " + type + " tasks to preempt");
      preemptTasks(tasksToPreempt);
    }
  }
660877
private boolean isNewStep(RouteProgress routeProgress) {
    boolean isNewStep = currentStep == null || !currentStep.equals(routeProgress.currentLegProgress().currentStep());
    currentStep = routeProgress.currentLegProgress().currentStep();
    resetAlertLevels(isNewStep);
    return isNewStep;
  }