Package org.h2.util

Class Task

  • All Implemented Interfaces:
    java.lang.Runnable

    public abstract class Task
    extends java.lang.Object
    implements java.lang.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
      private static java.util.concurrent.atomic.AtomicInteger counter  
      private java.lang.Exception ex  
      private boolean finished  
      private java.lang.Object result
      The result, if any.
      boolean stop
      A flag indicating the get() method has been called.
      private java.lang.Thread thread  
    • Constructor Summary

      Constructors 
      Constructor Description
      Task()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract void call()
      The method to be implemented.
      Task execute()
      Start the thread.
      Task execute​(java.lang.String threadName)
      Start the thread.
      java.lang.Object get()
      Calling this method will set the stop flag and wait until the thread is stopped.
      java.lang.Exception getException()
      Get the exception that was thrown in the call (if any).
      boolean isFinished()
      Whether the call method has returned (with or without exception).
      void join()
      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 Detail

      • counter

        private static final java.util.concurrent.atomic.AtomicInteger counter
      • stop

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

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

        private volatile boolean finished
      • thread

        private java.lang.Thread thread
      • ex

        private volatile java.lang.Exception ex
    • Constructor Detail

      • Task

        public Task()
    • Method Detail

      • call

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

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

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

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

        public java.lang.Object get()
        Calling this method will set the stop flag and wait until the thread is stopped.
        Returns:
        the result, or null
        Throws:
        java.lang.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 java.lang.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.