Having this wait declaration:
public final native void wait(long timeout) throws InterruptedException;
It could exit by InterruptedException, or by timeout, or because Notify/NotifyAll method was called in another thread, Exception is easy to catch but...
There is any way to know if the exits cause was timeout or notify?
EDIT:
This is a tricky way that could work, (although I don't like it)
long tBefore=System.currentTimeMillis();
wait(TIMEOUT);
if ((System.currentTimeMillis() - tBefore) > TIMEOUT)
{
//timeout
}
Semaphore
was better suited;Semaphore.tryAcquire(long timeout, TimeUnit unit)
returnsfalse
if the timeout has elapsed. – Isaisaacif ((System.currentTimeMillis() - tBefore) >= TIMEOUT)
– Mallarme