org.h2.util
Class Task

java.lang.Object
  extended by org.h2.util.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
protected  java.lang.Object result
          The result, if any.
protected  boolean stop
          A flag indicating the get() method has been called.
 
Constructor Summary
Task()
           
 
Method Summary
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 run()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stop

protected volatile boolean stop
A flag indicating the get() method has been called.


result

protected java.lang.Object result
The result, if any.

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