Package org.apache.tools.ant.util
Class WorkerAnt
java.lang.Object
java.lang.Thread
org.apache.tools.ant.util.WorkerAnt
- All Implemented Interfaces:
Runnable
A worker ant executes a single task in a background thread.
After the run, any exception thrown is turned into a BuildException, which can be
rethrown, the finished attribute is set, then notifyAll() is called,
so that anyone waiting on the same notify object gets woken up.
This class is effectively a superset of
org.apache.tools.ant.taskdefs.Parallel.TaskRunnable
- Since:
- Ant 1.8
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionGet any build exception.Get whatever was thrown, which may or may not be a buildException.getTask()
Get the taskboolean
Query the task/thread for being finished.void
Raise an exception if one was caughtvoid
run()
Run the task, which is skipped if null.void
waitUntilFinished
(long timeout) Block on the notify object and so wait until the thread is finished.Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, suspend, threadId, toString, yield
-
Field Details
-
ERROR_NO_TASK
-
-
Constructor Details
-
WorkerAnt
-
WorkerAnt
Create the worker, using the worker as the notification point.This does not start the thread, merely configures it.
- Parameters:
task
- the task
-
-
Method Details
-
getBuildException
Get any build exception. This would seem to be oversynchronised, but know that Java pre-1.5 can reorder volatile access. The synchronized attribute is to force an ordering.- Returns:
- the exception or null
-
getException
Get whatever was thrown, which may or may not be a buildException. Assertion: getException() instanceof BuildException <=> getBuildException()==getException()- Returns:
- the exception.
-
getTask
-
isFinished
public boolean isFinished()Query the task/thread for being finished. This would seem to be oversynchronised, but know that Java pre-1.5 can reorder volatile access. The synchronized attribute is to force an ordering.- Returns:
- true if the task is finished.
-
waitUntilFinished
Block on the notify object and so wait until the thread is finished.- Parameters:
timeout
- timeout in milliseconds- Throws:
InterruptedException
- if the execution was interrupted
-
rethrowAnyBuildException
public void rethrowAnyBuildException()Raise an exception if one was caught- Throws:
BuildException
- if one has been picked up
-
run
-