Class ParallelJob
- All Implemented Interfaces:
Serializable,Runnable,ArooaContextAware,ArooaSessionAware,Forceable,OptionallyTransient,PropertyChangeNotifier,Iconic,LogEnabled,Resettable,Stateful,Stoppable,Structural
- Author:
- Rob Gordon
- See Also:
ExecutorThrottleTypehas an example of limiting the number of concurrently executing jobs.
Description
A job which executes it's child jobs in parallel.
Once the child jobs are submitted, Oddjob's thread of execution continues
on out of this job. The state is set to ACTIVE and will continue to
change depending on the state of the child Jobs. The join
property can be used to hold the thread of execution until the
submitted jobs have finished executing - but it's use is discouraged.
See the property documentation below for more information.
The state of job, including its modification by the
stateOperator property is identical to SequentialJob
and is well documented there. Likewise with the transient property.
Example
Two jobs running in parallel. Note that the order of execution of the two child jobs is not predictable.
<oddjob>
<job>
<parallel>
<jobs>
<echo>This runs in parallel</echo>
<echo>With this which could be displayed first!</echo>
</jobs>
</parallel>
</job>
</oddjob>
Two services started in parallel. This might be quite useful if the
services took a long time to start - maybe because they loaded a lot
of data into a cache for instance.
<oddjob>
<job>
<cascade cascadeOn="COMPLETE">
<jobs>
<parallel>
<jobs>
<bean class="org.oddjob.jobs.structural.ServiceManagerTest$Lights" id="lights"/>
<bean class="org.oddjob.jobs.structural.ServiceManagerTest$MachineThatGoes" goes="ping" id="machine"/>
</jobs>
</parallel>
<echo>The lights are ${lights.are} and the machine goes ${machine.goes}.</echo>
</jobs>
</cascade>
</job>
</oddjob>
The CascadeJob will execute the final job only once both services
have started, and it will continue be in a STARTED after execution has
completed.
Adding a SERVICES stateOperator property will mean that parallel is COMPLETE once the services have started and so the whole cascade shows as complete.
<oddjob>
<job>
<cascade>
<jobs>
<parallel stateOperator="SERVICES">
<jobs>
<bean class="org.oddjob.jobs.structural.ServiceManagerTest$Lights" id="lights"/>
<bean class="org.oddjob.jobs.structural.ServiceManagerTest$MachineThatGoes" goes="ping" id="machine"/>
</jobs>
</parallel>
<echo>The lights are ${lights.are} and the machine goes ${machine.goes}.</echo>
</jobs>
</cascade>
</job>
</oddjob>
Examples elsewhere.
-
Field Summary
Fields inherited from class org.oddjob.framework.extend.StructuralJob
childHelper, destroy, stop, structuralState -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StateOperatorSubclasses must provide theStateOperatorthat will decide how to evaluate the children's state.Getter for State Operator.booleanisJoin()Should execution wait for all jobs to be executed before returning to calling code.booleanIs the component transient.voidsetJoin(boolean join) voidsetStateOperator(StateOperator stateOperator) voidsetTransient(boolean _transient) Methods inherited from class org.oddjob.framework.extend.SimultaneousStructural
execute, getExecutorService, onStop, setExecutorService, setJobs, startChildStateReflectorMethods inherited from class org.oddjob.framework.extend.StructuralJob
addStructuralListener, fireDestroyedState, force, getStateChanger, hardReset, iconHelper, isStop, onDestroy, onHardReset, onReset, onSoftReset, postStop, removeStructuralListener, run, softReset, stateHandler, stop, stopChildStateReflector, waitForChildrenOnStopMethods inherited from class org.oddjob.framework.extend.BasePrimary
configure, getName, logger, logger, loggerName, save, setName, toStringMethods inherited from class org.oddjob.framework.extend.BaseComponent
addIconListener, addPropertyChangeListener, addStateListener, configure, destroy, firePropertyChange, getArooaSession, iconForId, initialise, lastStateEvent, onConfigured, onInitialised, removeIconListener, removePropertyChangeListener, removeStateListener, save, setArooaContext, setArooaSessionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.oddjob.Stateful
addStateListener, lastStateEvent, removeStateListener
-
Constructor Details
-
ParallelJob
public ParallelJob()
-
-
Method Details
-
setStateOperator
- Parameters:
stateOperator- The state operator to be applied to children's states to derive our state.- Reference Property:
- stateOperator
- Required:
- No, default is ACTIVE.
Description
Set the way the children's state is evaluated and reflected by the parent. Values can be WORST, ACTIVE, or SERVICES. -
getStateOperator
Getter for State Operator.- Returns:
-
getInitialStateOp
Description copied from class:StructuralJobSubclasses must provide theStateOperatorthat will decide how to evaluate the children's state.- Specified by:
getInitialStateOpin classStructuralJob<Object>- Returns:
- A State Operator. Must not be null.
-
isJoin
public boolean isJoin()Description copied from class:SimultaneousStructuralShould execution wait for all jobs to be executed before returning to calling code.This property is intended to be overridden by sub classes that wish to give that choice to users.
- Overrides:
isJoinin classSimultaneousStructural- Returns:
- true for execution to wait for children. False for completion to be asynchronous.
-
setJoin
public void setJoin(boolean join) -
isTransient
public boolean isTransient()Description copied from interface:OptionallyTransientIs the component transient.- Specified by:
isTransientin interfaceOptionallyTransient- Returns:
- true if transient, false otherwise.
-
setTransient
public void setTransient(boolean _transient)
-