Package org.h2.util
Class Task
- java.lang.Object
-
- org.h2.util.Task
-
- All Implemented Interfaces:
java.lang.Runnable
public abstract class Task extends java.lang.Object implements java.lang.RunnableA 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.AtomicIntegercounterprivate java.lang.Exceptionexprivate booleanfinishedprivate java.lang.ObjectresultThe result, if any.booleanstopA flag indicating the get() method has been called.private java.lang.Threadthread
-
Constructor Summary
Constructors Constructor Description Task()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidcall()The method to be implemented.Taskexecute()Start the thread.Taskexecute(java.lang.String threadName)Start the thread.java.lang.Objectget()Calling this method will set the stop flag and wait until the thread is stopped.java.lang.ExceptiongetException()Get the exception that was thrown in the call (if any).booleanisFinished()Whether the call method has returned (with or without exception).voidjoin()Stop the thread and wait until it is no longer running.voidrun()
-
-
-
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
-
-
Method Detail
-
call
public abstract void call() throws java.lang.ExceptionThe method to be implemented.- Throws:
java.lang.Exception- any exception is wrapped in a RuntimeException
-
run
public void run()
- Specified by:
runin interfacejava.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.
-
-