Top Description Fields Constructors Methods
org.apache.tools.ant.util

public Class WorkerAnt

extends Thread
Class Inheritance
Imports
org.apache.tools.ant.BuildException, .Task

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

Field Summary

Modifier and TypeField and Description
private volatile BuildException
public static final String
ERROR_NO_TASK

Error message if invoked with no task

private volatile Throwable
private volatile boolean
private Object
private Task
Inherited from java.lang.Thread:
MAX_PRIORITYMIN_PRIORITYNORM_PRIORITY

Constructor Summary

AccessConstructor and Description
public
WorkerAnt(Task
the task
task
,
Object
what to notify
notify
)

Create the worker.

public
WorkerAnt(Task
the task
task
)

Create the worker, using the worker as the notification point.

Method Summary

Modifier and TypeMethod and Description
private synchronized void
caught(Throwable
what was caught earlier
thrown
)

Handle a caught exception, by recording it and possibly wrapping it in a BuildException for later rethrowing.

public synchronized BuildException

Returns:

the exception or null
getBuildException
()

Get any build exception.

public synchronized Throwable

Returns:

the exception.
getException
()

Get whatever was thrown, which may or may not be a buildException.

public Task

Returns:

the task
getTask
()

Get the task

public synchronized boolean

Returns:

true if the task is finished.
isFinished
()

Query the task/thread for being finished.

public void
rethrowAnyBuildException()

Raise an exception if one was caught

public void
run()

Overrides java.lang.Thread.run.

Implements java.lang.Runnable.run.

Run the task, which is skipped if null.
public void
waitUntilFinished(long
timeout in milliseconds
timeout
)

Block on the notify object and so wait until the thread is finished.

Inherited from java.lang.Thread:
activeCountcheckAccessclonecountStackFramescurrentThreaddumpStackenumerategetAllStackTracesgetContextClassLoadergetDefaultUncaughtExceptionHandlergetIdgetNamegetPrioritygetStackTracegetStategetThreadGroupgetUncaughtExceptionHandlerholdsLockinterruptinterruptedisAliveisDaemonisInterruptedisVirtualjoinjoinjoinjoinofPlatformofVirtualonSpinWaitresumesetContextClassLoadersetDaemonsetDefaultUncaughtExceptionHandlersetNamesetPrioritysetUncaughtExceptionHandlersleepsleepsleepstartstartVirtualThreadstopsuspendthreadIdtoStringyield

Field Detail

buildExceptionback to summary
private volatile BuildException buildException
ERROR_NO_TASKback to summary
public static final String ERROR_NO_TASK

Error message if invoked with no task

exceptionback to summary
private volatile Throwable exception
finishedback to summary
private volatile boolean finished
notifyback to summary
private Object notify
taskback to summary
private Task task

Constructor Detail

WorkerAntback to summary
public WorkerAnt(Task task, Object notify)

Create the worker.

This does not start the thread, merely configures it.

Parameters
task:Task

the task

notify:Object

what to notify

WorkerAntback to summary
public WorkerAnt(Task task)

Create the worker, using the worker as the notification point.

This does not start the thread, merely configures it.

Parameters
task:Task

the task

Method Detail

caughtback to summary
private synchronized void caught(Throwable thrown)

Handle a caught exception, by recording it and possibly wrapping it in a BuildException for later rethrowing.

Parameters
thrown:Throwable

what was caught earlier

getBuildExceptionback to summary
public synchronized BuildException 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:BuildException

the exception or null

getExceptionback to summary
public synchronized Throwable getException()

Get whatever was thrown, which may or may not be a buildException. Assertion: getException() instanceof BuildException <=> getBuildException()==getException()

Returns:Throwable

the exception.

getTaskback to summary
public Task getTask()

Get the task

Returns:Task

the task

isFinishedback to summary
public synchronized 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:boolean

true if the task is finished.

rethrowAnyBuildExceptionback to summary
public void rethrowAnyBuildException()

Raise an exception if one was caught

Exceptions
BuildException:
if one has been picked up
runback to summary
public void run()

Overrides java.lang.Thread.run.

Implements java.lang.Runnable.run.

Run the task, which is skipped if null. When invoked again, the task is re-run.

waitUntilFinishedback to summary
public void waitUntilFinished(long timeout) throws InterruptedException

Block on the notify object and so wait until the thread is finished.

Parameters
timeout:long

timeout in milliseconds

Exceptions
InterruptedException:
if the execution was interrupted