public class Runner
extends java.lang.Object
RaceRunnable
interface and pass it to the constructor of this
class. Then, call the run()
method; when this method returns, use
getWinner()
to get the winner of the race.Constructor and Description |
---|
Runner(java.util.Collection<? extends RaceRunnable> runnables,
int timeout)
Constructs a new
Runner . |
Runner(RaceRunnable[] runnables,
int timeout)
Constructs a new
Runner . |
Modifier and Type | Method and Description |
---|---|
RaceRunnable |
getWinner()
Returns the winner of the race, or null if no winner.
|
boolean |
isTimeoutExpired()
Returns true if the timeout has expired, false otherwise.
|
void |
run()
Start running the runnables, and block until a runnable wins the race,
all runnables terminate without winning, or the timeout expires.
|
public Runner(java.util.Collection<? extends RaceRunnable> runnables, int timeout)
Runner
.runnables
- a collection of runnables implementing the
RaceRunnable
interfacetimeout
- the timeout (in seconds)public Runner(RaceRunnable[] runnables, int timeout)
Runner
.runnables
- an array of runnables implementing the
RaceRunnable
interfacetimeout
- the timeout (in seconds)public void run() throws java.lang.InterruptedException
java.lang.InterruptedException
public RaceRunnable getWinner()
public boolean isTimeoutExpired()