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 Summary

    Fields
    Modifier and Type
    Field
    Description
    boolean
    A flag indicating the get() method has been called.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract void
    The method to be implemented.
    Start the thread.
    execute(String threadName)
    Start the thread.
    get()
    Calling this method will set the stop flag and wait until the thread is stopped.
    Get the exception that was thrown in the call (if any).
    boolean
    Whether the call method has returned (with or without exception).
    void
    Stop the thread and wait until it is no longer running.
    void
    run()
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • stop

      public volatile boolean stop
      A flag indicating the get() method has been called.
  • 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.