|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eclipse.jgit.util.io.InterruptTimer
public final class InterruptTimer
Triggers an interrupt on the calling thread if it doesn't complete a block.
Classes can use this to trip an alarm interrupting the calling thread if it doesn't complete a block within the specified timeout. Typical calling pattern is:
private InterruptTimer myTimer = ...; void foo() { try { myTimer.begin(timeout); // work } finally { myTimer.end(); } }
An InterruptTimer is not recursive. To implement recursive timers, independent InterruptTimer instances are required. A single InterruptTimer may be shared between objects which won't recursively call each other.
Each InterruptTimer spawns one background thread to sleep the specified time
and interrupt the thread which called begin(int)
. It is up to the
caller to ensure that the operations within the work block between the
matched begin and end calls tests the interrupt flag (most IO operations do).
To terminate the background thread, use terminate()
. If the
application fails to terminate the thread, it will (eventually) terminate
itself when the InterruptTimer instance is garbage collected.
TimeoutInputStream
Constructor Summary | |
---|---|
InterruptTimer()
Create a new timer with a default thread name. |
|
InterruptTimer(String threadName)
Create a new timer to signal on interrupt on the caller. |
Method Summary | |
---|---|
void |
begin(int timeout)
Arm the interrupt timer before entering a blocking operation. |
void |
end()
Disable the interrupt timer, as the operation is complete. |
void |
terminate()
Shutdown the timer thread, and wait for it to terminate. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public InterruptTimer()
public InterruptTimer(String threadName)
The timer thread is created in the calling thread's ThreadGroup.
threadName
- name of the timer thread.Method Detail |
---|
public void begin(int timeout)
timeout
- number of milliseconds before the interrupt should trigger.
Must be > 0.public void end()
public void terminate()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |