Class AsyncExecutionSupport

java.lang.Object
org.oddjob.framework.util.AsyncExecutionSupport

public class AsyncExecutionSupport extends Object
Helper class for things that execute jobs in parallel. This class ensures that all simultaneous executions are tracked, can be stopped, can be waited for and allows an action to be run on completion of all the simultaneous jobs.
Author:
rob
See Also:
  • Constructor Details

    • AsyncExecutionSupport

      public AsyncExecutionSupport(Runnable onCompleteAction, Consumer<? super Throwable> exceptionHandler)
      Create a new instance.
      Parameters:
      onCompleteAction -
  • Method Details

    • submitJob

      public void submitJob(Executor executor, Runnable job)
    • joinOnAllJobs

      public void joinOnAllJobs() throws InterruptedException, ExecutionException
      Throws:
      InterruptedException
      ExecutionException
    • startWatchingJobs

      public void startWatchingJobs()
      Start watching jobs for them to finish executing.
    • cancelAllPendingJobs

      public void cancelAllPendingJobs()
      Cancel all pending jobs. This will not stop jobs already executing but will cancel pending jobs. Stopping jobs is left to calling code.

      Also stop watching executing jobs.

    • reset

      public void reset()
      Reset the internal state so that it can be used again with a new set of jobs.
    • size

      public int size()
      The number of simultaneous job currently being tracked.
      Returns: