Package org.h2.util

Class Task

java.lang.Object
org.h2.util.Task
All Implemented Interfaces:
Runnable

public abstract class Task extends Object implements Runnable
A method call that is executed in a separate thread. If the method throws an exception, it is wrapped in a RuntimeException.
  • Field Details

    • counter

      private static final AtomicInteger counter
    • stop

      public volatile boolean stop
      A flag indicating the get() method has been called.
    • result

      private volatile Object result
      The result, if any.
    • finished

      private volatile boolean finished
    • thread

      private Thread thread
    • ex

      private volatile Exception ex
  • Constructor Details

    • Task

      public Task()
  • Method Details

    • call

      public abstract void call() throws Exception
      The method to be implemented.
      Throws:
      Exception - any exception is wrapped in a RuntimeException
    • run

      public void run()
      Specified by:
      run in interface Runnable
    • execute

      public Task execute()
      Start the thread.
      Returns:
      this
    • execute

      public Task execute(String threadName)
      Start the thread.
      Parameters:
      threadName - the name of the thread
      Returns:
      this
    • get

      public Object get()
      Calling this method will set the stop flag and wait until the thread is stopped.
      Returns:
      the result, or null
      Throws:
      RuntimeException - if an exception in the method call occurs
    • isFinished

      public boolean isFinished()
      Whether the call method has returned (with or without exception).
      Returns:
      true if yes
    • getException

      public Exception getException()
      Get the exception that was thrown in the call (if any).
      Returns:
      the exception or null
    • join

      public void join()
      Stop the thread and wait until it is no longer running. Exceptions are ignored.