Results 1 to 2 of 2
Thread: WAIT method question
- 03-14-2011, 10:24 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 6
- Rep Power
- 0
WAIT method question
I'm using 'public final void wait(long timeout, int nanos)' on a monitor.
Reading the javadoc I've found the following sentences:
* Another thread notifies threads waiting on this object's monitor to wake up either through a call to the notify method or the notifyAll method.
* The timeout period, specified by timeout milliseconds plus nanos nanoseconds arguments, has elapsed.
How can I differentiate between the two cases?
If the timeout period has elapsed I want to throw an exception and in the other case I want to continue to the following steps.
Thank you.
Alex
- 03-14-2011, 11:37 AM #2
Member
- Join Date
- Mar 2011
- Posts
- 2
- Rep Power
- 0
You may either:
-measure the time spent waiting, and if it's big enough, throw an exception. This is simple to implement but you could get some false positives. If your request is meant to be a debugging facility, it is likely just fine, if you keep in mind the thread might in fact have been notified.
-instead of timed wait, use an infinite wait + a separate watchdog thread. If the watchdog interrupts your thread, you get an interruptedException. If the watchdog interrups the other thread after returning from wait, the thread gets its interrupt flag set - you can check the flag after resetting the watchdog.
-create a new watchdog thread every time you wait. This causes considerable performance penalty but it simplifies the implementation a bit.
There might other option I haven't thought of, please share your ideas.
Similar Threads
-
Wait method and sleep method
By chathura87 in forum New To JavaReplies: 3Last Post: 03-01-2011, 05:04 PM -
Why would a String class need a wait() method?
By javanb in forum New To JavaReplies: 8Last Post: 12-06-2010, 01:36 PM -
Wait() Question
By rsvr in forum Threads and SynchronizationReplies: 3Last Post: 04-27-2010, 03:39 PM -
need help with question(method & array)
By highschool in forum New To JavaReplies: 5Last Post: 02-10-2010, 05:06 PM -
method question
By xplayerr in forum New To JavaReplies: 7Last Post: 11-11-2009, 04:13 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks