Class ImmediateJobScheduler
- All Implemented Interfaces:
JobScheduler
JobScheduler that runs jobs on the thread that submits them, with a thread count of
one.
A submit from a thread that is not already running this scheduler's jobs runs the job before
returning, along with every job submitted while it runs. Jobs submitted from within a running job are queued rather
than run recursively, and the queue is drained most recently submitted first, so nested work runs depth-first rather
than in submission order.
Only one thread may run this scheduler's jobs at a time: a submit from any other thread while jobs are running throws
IllegalCallerException. A job that completes asynchronously must therefore resume on the running thread, or
after the jobs have finished. An Error thrown by a job propagates out of the submit that is running it.
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.deephaven.engine.table.impl.util.JobScheduler
JobScheduler.IterateAction<CONTEXT_TYPE extends JobScheduler.JobThreadContext>, JobScheduler.IterateResumeAction<CONTEXT_TYPE extends JobScheduler.JobThreadContext>, JobScheduler.IterationManager<CONTEXT_TYPE extends JobScheduler.JobThreadContext>, JobScheduler.JobThreadContext, JobScheduler.Submission -
Field Summary
Fields inherited from interface io.deephaven.engine.table.impl.util.JobScheduler
DEFAULT_CONTEXT, DEFAULT_CONTEXT_FACTORY, UNREPORTABLE_JOB_ERROR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> TawaitCompletion(@NotNull CompletableFuture<T> future) Return the result offuture, which the jobs have completed by the timesubmit(io.deephaven.engine.context.ExecutionContext, java.lang.Runnable, io.deephaven.base.log.LogOutputAppendable, java.util.function.Consumer<java.lang.Exception>)returns.The performance statistics of all runnables that have been completed off-thread, or null if all were executed in the current thread.submit(ExecutionContext executionContext, Runnable runnable, LogOutputAppendable description, Consumer<Exception> onError) Cause runnable to be executed.intHow many threads exist in the job scheduler? The job submitters can use this value to determine how many sub-jobs to split work into.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.deephaven.engine.table.impl.util.JobScheduler
invokeParallel, iterateParallel, iterateParallel, iterateSerial
-
Constructor Details
-
ImmediateJobScheduler
public ImmediateJobScheduler()
-
-
Method Details
-
submit
public JobScheduler.Submission submit(ExecutionContext executionContext, Runnable runnable, LogOutputAppendable description, Consumer<Exception> onError) Description copied from interface:JobSchedulerCause runnable to be executed.A scheduler runs every job it accepts: at once, after queuing it, or, when it has no thread free and no queue to hold the job, on the calling thread. A scheduler that cannot take a job at all throws instead, and the job does not run.
- Specified by:
submitin interfaceJobScheduler- Parameters:
executionContext- the execution context to run it underrunnable- the runnable to executedescription- a description for loggingonError- a routine to call if an exception occurs while running runnable- Returns:
- the accepted job, which the submitter may withdraw while no thread has started it
-
awaitCompletion
public <T> T awaitCompletion(@NotNull @NotNull CompletableFuture<T> future) throws InterruptedException, ExecutionException Return the result offuture, which the jobs have completed by the timesubmit(io.deephaven.engine.context.ExecutionContext, java.lang.Runnable, io.deephaven.base.log.LogOutputAppendable, java.util.function.Consumer<java.lang.Exception>)returns.- Specified by:
awaitCompletionin interfaceJobScheduler- Parameters:
future- the future to wait for- Returns:
- the result of
future - Throws:
AssertionFailure- iffutureis not doneInterruptedException- if the calling thread is interrupted while waitingExecutionException- iffuturecompleted exceptionally
-
getAccumulatedPerformance
Description copied from interface:JobSchedulerThe performance statistics of all runnables that have been completed off-thread, or null if all were executed in the current thread.When initializing an operation, the
OperationInitializerJobSchedulerexecutes the completion callback as part of another task. Therefore, you must not read the accumulated performance from the completion callback when initializing an operation; as it could miss data from some of the tasks. Furthermore, even though the completion callback identifies the result as ready does not mean that the completion callback has actually completed. To guard against this theOperationInitializerJobSchedulerwaits for all jobs to be complete before returning theBasePerformanceEntry. Therefore, if you call this from a completion callback, then the operation will hang.ExecutorJobSchedulerwaits the same way, so the same applies to it.It never runs a job itself, so call it only once every job has started: after
JobScheduler.awaitCompletion(java.util.concurrent.CompletableFuture<T>)orJobScheduler.invokeParallel(io.deephaven.engine.context.ExecutionContext, io.deephaven.base.log.LogOutputAppendable, java.util.function.Supplier<CONTEXT_TYPE>, int, int, io.deephaven.engine.table.impl.util.JobScheduler.IterateAction<CONTEXT_TYPE>), which leave no job waiting for a thread. Otherwise it may wait for a job queued behind threads that are themselves waiting, perhaps for a lock the calling thread holds.- Specified by:
getAccumulatedPerformancein interfaceJobScheduler
-
threadCount
public int threadCount()Description copied from interface:JobSchedulerHow many threads exist in the job scheduler? The job submitters can use this value to determine how many sub-jobs to split work into.- Specified by:
threadCountin interfaceJobScheduler
-