Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

This might be controversial, but I just realized I very seldom use wait and notify directly. Instead, I use some higher-level construct from the java.util.concurrent package. Are there use cases where wait and notify are the only solution or should they only be used when building higher-level constructs?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
378 views
Welcome To Ask or Share your Answers For Others

1 Answer

From my POV, you are absolutely right : it's far better to use higher-order constructs like the ones from java.util.concurrent. The wait/notify system is error-prone, low-level, and has issues (like missed signals - the "notifier" emits the signal before the "waiter" calls wait()).

So, I cannot see any case where using wait/notify would be better. Except if you're stuck with Java pre-1.5 of course.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...