New behavior allows for the ant script to specify a maximum number of
threads that will be executed in parallel. One should be very careful about
using the waitFor task when specifying threadCount
as it can cause deadlocks if the number of threads is too small or if one of
the nested tasks fails to execute completely. The task selection algorithm
will insure that the tasks listed before a task have started before that
task is started, but it will not insure a successful completion of those
tasks or that those tasks will finish first (i.e. it's a classic race
condition).
| Modifier and Type | Class and Description |
|---|---|
| public static class | Parallel.TaskList
Class which holds a list of tasks to execute |
| private class | Parallel.TaskRunnable
thread that execs a task |
| Modifier and Type | Field and Description |
|---|---|
| private Parallel. | daemonTasks
The daemon task list if any |
| private StringBuffer | exceptionMessage
Accumulation of exceptions messages from all nested tasks |
| private boolean | failOnAny
Indicates whether failure of any of the nested tasks should end execution |
| private Throwable | firstException
The first exception encountered |
| private Integer | firstExitStatus
The status of the first ExitStatusException. |
| private Location | firstLocation
The location of the first exception |
| private Vector | nestedTasks
Collection holding the nested tasks |
| private static final int | |
| private int | numExceptions
Number of exceptions from nested tasks |
| private int | numThreads
Total number of threads to run |
| private int | numThreadsPerProcessor
Total number of threads per processor to run. |
| private final Object | semaphore
Semaphore to notify of completed threads |
| private volatile boolean | stillRunning
Indicates threads are still running and new threads can be issued |
| private boolean | timedOut
Indicates that the execution timedout |
| private long | timeout
The timeout period in milliseconds |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | addDaemons(Parallel.
The tasks to be executed as daemon. daemonTasksAdd a group of daemon threads |
| public void | addTask(Task
Nested task to be executed in parallel nestedTask)Implements org. |
| public void | |
| private void | killAll(Parallel.
The list of tasks that may currently be running. runningDoesn't do anything if all threads where already gone, else it tries to interrupt the threads 100 times. |
| private void | |
| public void | setFailOnAny(boolean
if true any nested task failure causes parallel to
complete. failOnAny)Control whether a failure in a nested task halts execution. |
| public void | setPollInterval(int
New value of property pollInterval. pollInterval)Interval to poll for completed threads when threadCount or threadsPerProcessor is specified. |
| public void | setThreadCount(int
total number of threads. numThreads)Statically determine the maximum number of tasks to execute simultaneously. |
| public void | setThreadsPerProcessor(int
Number of threads to create per available
processor. numThreadsPerProcessor)Dynamically generates the number of threads to execute based on the
number of available processors (via
|
| public void | |
| private void | |
| private void |
| daemonTasks | back to summary |
|---|---|
| private Parallel. The daemon task list if any | |
| exceptionMessage | back to summary |
|---|---|
| private StringBuffer exceptionMessage Accumulation of exceptions messages from all nested tasks | |
| failOnAny | back to summary |
|---|---|
| private boolean failOnAny Indicates whether failure of any of the nested tasks should end execution | |
| firstException | back to summary |
|---|---|
| private Throwable firstException The first exception encountered | |
| firstExitStatus | back to summary |
|---|---|
| private Integer firstExitStatus The status of the first ExitStatusException. | |
| firstLocation | back to summary |
|---|---|
| private Location firstLocation The location of the first exception | |
| nestedTasks | back to summary |
|---|---|
| private Vector<Task> nestedTasks Collection holding the nested tasks | |
| NUMBER_TRIES | back to summary |
|---|---|
| private static final int NUMBER_TRIES | |
| numExceptions | back to summary |
|---|---|
| private int numExceptions Number of exceptions from nested tasks | |
| numThreads | back to summary |
|---|---|
| private int numThreads Total number of threads to run | |
| numThreadsPerProcessor | back to summary |
|---|---|
| private int numThreadsPerProcessor Total number of threads per processor to run. | |
| semaphore | back to summary |
|---|---|
| private final Object semaphore Semaphore to notify of completed threads | |
| stillRunning | back to summary |
|---|---|
| private volatile boolean stillRunning Indicates threads are still running and new threads can be issued | |
| timedOut | back to summary |
|---|---|
| private boolean timedOut Indicates that the execution timedout | |
| timeout | back to summary |
|---|---|
| private long timeout The timeout period in milliseconds | |
| Parallel | back to summary |
|---|---|
| public Parallel() | |
| addDaemons | back to summary |
|---|---|
| public void addDaemons(Parallel. Add a group of daemon threads | |
| addTask | back to summary |
|---|---|
| public void addTask(Task nestedTask) Implements org. Add a nested task to execute in parallel. | |
| execute | back to summary |
|---|---|
| public void execute() throws BuildException Overrides org. Execute the parallel tasks
| |
| killAll | back to summary |
|---|---|
| private void killAll(Parallel. Doesn't do anything if all threads where already gone, else it tries to interrupt the threads 100 times.
| |
| processExceptions | back to summary |
|---|---|
| private void processExceptions(Parallel. | |
| setFailOnAny | back to summary |
|---|---|
| public void setFailOnAny(boolean failOnAny) Control whether a failure in a nested task halts execution. Note that the task will complete but existing threads will continue to run - they are not stopped
| |
| setPollInterval | back to summary |
|---|---|
| public void setPollInterval(int pollInterval) Interval to poll for completed threads when threadCount or threadsPerProcessor is specified. Integer in milliseconds.; optional
| |
| setThreadCount | back to summary |
|---|---|
| public void setThreadCount(int numThreads) Statically determine the maximum number of tasks to execute
simultaneously. If there are less tasks than threads then all will be
executed at once, if there are more then only
| |
| setThreadsPerProcessor | back to summary |
|---|---|
| public void setThreadsPerProcessor(int numThreadsPerProcessor) Dynamically generates the number of threads to execute based on the
number of available processors (via
| |
| setTimeout | back to summary |
|---|---|
| public void setTimeout(long timeout) Sets the timeout on this set of tasks. If the timeout is reached before the other threads complete, the execution of this task completes with an exception. Note that existing threads continue to run.
| |
| spinThreads | back to summary |
|---|---|
| private void spinThreads() throws BuildException Spin up required threads with a maximum number active at any given time.
| |
| updateThreadCounts | back to summary |
|---|---|
| private void updateThreadCounts() Determine the number of threads based on the number of processors | |
| Modifier and Type | Field and Description |
|---|---|
| private List | tasks
Collection holding the nested tasks |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | addTask(Task
Nested task to be executed in parallel.
must not be null. nestedTask)Implements org. |
| tasks | back to summary |
|---|---|
| private List<Task> tasks Collection holding the nested tasks | |
| TaskList | back to summary |
|---|---|
| public TaskList() | |
| addTask | back to summary |
|---|---|
| public void addTask(Task nestedTask) Implements org. Add a nested task to execute in parallel (asynchronously).
| |
| Modifier and Type | Field and Description |
|---|---|
| private Throwable | |
| private boolean | |
| private Task | |
| private volatile Thread |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public Throwable | Returns: an exception or null for no exception/not yet finishedget any exception that got thrown during execution; |
| pack-priv void | |
| pack-priv boolean | Returns: Returns true when the task is finished.Provides the indicator that the task has been finished. |
| public void | run()
Implements java. |
| exception | back to summary |
|---|---|
| private Throwable exception | |
| finished | back to summary |
|---|---|
| private boolean finished | |
| task | back to summary |
|---|---|
| private Task task | |
| thread | back to summary |
|---|---|
| private volatile Thread thread | |
| TaskRunnable | back to summary |
|---|---|
| pack-priv TaskRunnable(Task task) Construct a new TaskRunnable.
| |
| getException | back to summary |
|---|---|
| public Throwable getException() get any exception that got thrown during execution;
| |
| interrupt | back to summary |
|---|---|
| pack-priv void interrupt() | |
| isFinished | back to summary |
|---|---|
| pack-priv boolean isFinished() Provides the indicator that the task has been finished.
| |
| run | back to summary |
|---|---|
| public void run() Implements java. Executes the task within a thread and takes care about Exceptions raised within the task.
| |