|
Forward Computing and Control Pty. Ltd. Threads Package V1.0.3 2005/04/11 |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.Date
au.com.forward.threads.TimeOut
public class TimeOut
This class sets a timeout time which can by used by mulitple join() statements to specify the total time required for a number of threads to complete. Typical use is:-
thread_1.start(); // start all the threads thread_2.start(); thread_3.start(); TimeOut timeOut = new TimeOut(5000); // time out expires in 5 seconds from now ThreadReturn.join(thread_1,timeOut.timeRemaining()); ThreadReturn.join(thread_2,timeOut.timeRemaining()); ThreadReturn.join(thread_3,timeOut.timeRemaining());This sets the timeout at 5 seconds from the time the
TimeOut
constructor
is executed. This sets an absolute end time of now + 5 seconds.
The first join()
statement receives timeout arguement of the absolute end time - now in
milliseconds. When this join()
returns the following join()
receives
a timeout arguement of only the remaining time (in milliseconds) and so on.
This ensures that each of the three threads have
at most 5 seconds to complete their tasks.
If the absolute end time has been passed then timeRemaining()
returns 1 millisecond as a minimum value
because 0 causes join()
to wait forever and negative numbers are not valid arguements for
join()
. This means that maximum timeout is actually 5 sec + 2 milliseconds for this example
or in general
maximum timeout = constructor timeout + (no. of thread joins - 1) * 1mS
Constructor Summary | |
---|---|
TimeOut(long milliseconds)
Creates a new timeout with an absolute time of now + milliseconds |
Method Summary | |
---|---|
long |
timeRemaining()
Returns the number of milliseconds remaining from now. |
Methods inherited from class java.util.Date |
---|
after, before, clone, compareTo, equals, getDate, getDay, getHours, getMinutes, getMonth, getSeconds, getTime, getTimezoneOffset, getYear, hashCode, parse, setDate, setHours, setMinutes, setMonth, setSeconds, setTime, setYear, toGMTString, toLocaleString, toString, UTC |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public TimeOut(long milliseconds)
milliseconds
milliseconds
- the timeout.Method Detail |
---|
public long timeRemaining()
|
Forward Computing and Control Pty. Ltd. Threads Package V1.0.3 2005/04/11 |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |