Is using Object.wait and Object.notify directly a code smell?

前端 未结 2 2006
抹茶落季
抹茶落季 2020-12-20 19:10

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

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-20 19:42

    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.

提交回复
热议问题