/** * Prepends a task to the front of the queue and makes sure a worker thread is running, unless the * queue has been suspended. */ public void executeFirst(Runnable task) { synchronized (internalLock) { queue.addFirst(task); } startQueueWorker(); }
/** * Adds a task to the queue and makes sure a worker thread is running, unless the queue has been * suspended. * * <p>If this method throws, e.g. a {@code RejectedExecutionException} from the delegate executor, * execution of tasks will stop until a call to this method or to {@link #resume()} is * made. */ public void execute(Runnable task) { synchronized (internalLock) { queue.add(task); } startQueueWorker(); }
/** * Continue execution of tasks after a call to {@link #suspend()}. More accurately, decreases the * suspension counter, as has been incremented by calls to {@link #suspend}, and resumes execution * if the suspension counter is zero. * * <p>If this method throws, e.g. a {@code RejectedExecutionException} from the delegate executor, * execution of tasks will stop until a call to this method or to {@link #execute(Runnable)} or * {@link #executeFirst(Runnable)} is made. * * @throws java.lang.IllegalStateException if this executor is not suspended. */ public void resume() { synchronized (internalLock) { Preconditions.checkState(suspensions > 0); suspensions--; } startQueueWorker(); }