SCJP , SCJD. (IBM 142 in progress).
SCJP , SCJD. (IBM 142 in progress).
"I'm not back." - Bill Harding, Twister
SCJP , SCJD. (IBM 142 in progress).
SCJP , SCJD. (IBM 142 in progress).
"I'm not back." - Bill Harding, Twister
"I'm not back." - Bill Harding, Twister
SCJP , SCJD. (IBM 142 in progress).
Originally posted by Jim Yingst:
[b][TM]: The alternative solution I suggest is as follows
[...]
Probably. However - who sends the notify() or notifyAll() signal? And does anyone ever set flag = false? Those could create additional problems.
Since flag is mutable data which is accessed inside more than one thread, you should probably move the "if (flag == true)" check inside the second sync block. Otherwise you may sometimes get incorrect information.
Hope that helps...
SCJP , SCJD. (IBM 142 in progress).
"I'm not back." - Bill Harding, Twister
"I'm not back." - Bill Harding, Twister
Originally posted by Jim Yingst:
The thing is: how would you know if the second thread had already sent the notify() signal, before the first thread entered the wait()? If you enter wait() after notify() was already sent, you may wait forever .. Usually you need both threads to share some information (e.g. a flag) so that the thread-which-waits can determine whether the condition-it-waits-for has already occurred or not.
[ May 16, 2006: Message edited by: Jim Yingst ][/QB]
SCJP , SCJD. (IBM 142 in progress).
"I'm not back." - Bill Harding, Twister
SCJP , SCJD. (IBM 142 in progress).
The two armies met. But instead of battle, they decided to eat some pie and contemplate this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|