public class Wait extends Object
These methods do not throw InterruptedException
. Their
implementation is based on methods in Object
or
Thread
, but have their own handling of
InterruptedExeptions. They may be used as drop-in
replacements for the corresponding methods in Object
and
Thread
.
If the underlying methods throws an AsynchronouslyInterruptedException
or an instance of a subclass, an AsynchronouslyInterruptedError
is
thrown.
This can be used to avoid an endless loop when performing
wait(), sleep() or join() in a loop with a catch clause to ignore
InterruptedException. In this case, a pending
AsynchronouslyInterruptedException would be thrown immediately on
the call to wait/sleep/join, causing a live lock.
Constructor and Description |
---|
Wait() |
Modifier and Type | Method and Description |
---|---|
static void |
checkForAsynchronouslyInterruptedException(InterruptedException exception)
Check if given InterruptedException is an
AsynchronouslyInterruptedException.
|
static void |
checkPendingAsynchronouslyInterruptedException()
In case there is a javax.realtime.AsynchronouslyInterruptedException
pending for the current thread, this pending exception is thrown.
|
static void |
join(Thread thread)
Wait for termination of a given thread.
|
static InterruptedException |
newInterruptedException()
Create a new InterruptedException.
|
static void |
sleep(long ms)
Convenience method.
|
static void |
sleep(long ms,
int ns)
Sleep for a given amount of time and ignore all interrupts() or
ThreadDeath exceptions.
|
static void |
throwInterruptedException()
throws a InterruptedException.
|
static void |
wait(Object obj)
Convenience method.
|
static void |
wait(Object obj,
long ms)
Convenience method.
|
static void |
wait(Object obj,
long ms,
int ns)
Wait for a notify on a given object using
Object.wait(long, int)
and ignore all interrupts() or ThreadDeath exceptions. |
public static void wait(Object obj, long ms, int ns)
Object.wait(long, int)
and ignore all interrupts() or ThreadDeath exceptions. Remember the
interrupted() state in the current thread.
This routine only returns after a notify occurred or the timeout
has expired. Any interrupt() that occurred will be recored in the
isInterrupted() state of the current thread.IllegalMonitorStateException
- if the current thread did
not enter obj's monitor.AsynchronouslyInterruptedError
- if the wait was
interrupted by an AsynchronouslyInterruptedException.obj
- the object to wait for.ms
- the timeout in milliseconds, 0 for none.ns
- the timeout in nanoseconds, 0 for none.public static void wait(Object obj, long ms)
obj
- the object to wait for.ms
- the timeout in milliseconds, 0 for none.public static void wait(Object obj)
obj
- the object to wait for.public static void sleep(long ms, int ns)
IllegalArgumentException
- if millis or nanos is negative
or nanos is larger than 999999.AsynchronouslyInterruptedError
- if the wait was
interrupted by an AsynchronouslyInterruptedException.ms
- the timeout in milliseconds.ns
- the timeout in nanoseconds.public static void sleep(long ms)
ms
- the timeout in milliseconds.public static void join(Thread thread)
AsynchronouslyInterruptedError
- if the wait was
interrupted by an AsynchronouslyInterruptedException.thread
- the thread whose termination we are waiting for.public static InterruptedException newInterruptedException() throws AsynchronouslyInterruptedException
AsynchronouslyInterruptedException
- in case of a pending
javax.realtime.AsynchronouslyInterruptedException.public static void throwInterruptedException() throws InterruptedException
InterruptedExcpetion
- in any case.InterruptedException
public static void checkForAsynchronouslyInterruptedException(InterruptedException exception) throws AsynchronouslyInterruptedError
AsynchronouslyInterruptedError
exception
- an InterruptedExceptionpublic static void checkPendingAsynchronouslyInterruptedException() throws AsynchronouslyInterruptedError
AsynchronouslyInterruptedError
- in case an
AsynchronouslyInterruptedException was pendingaicas GmbH, Karlsruhe, Germany —www.aicas.com
Copyright © 2001-2019 aicas GmbH. All Rights Reserved.