Wait, Notify and Exceptions

K

kgw0news

Since wait can already throw an exception,
why not allow notify to pass one to be taken at the wait if any?

Right now if I have a thread waiting for an event to complete, I have
to set some state info
that the thread must check after the wait to decide if the event
succeeded.
 
G

Gordon Beaton

Since wait can already throw an exception, why not allow notify to
pass one to be taken at the wait if any?

Right now if I have a thread waiting for an event to complete, I
have to set some state info that the thread must check after the
wait to decide if the event succeeded.

Consider what will happen if the event occurs before you reach wait().

You need that state check regardless, and in a loop:

synchronized (o) {
while (!eventHasFired()) {
o.wait();
}
}

/gordon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top