Condition vs wait notify mechanism

前端 未结 5 1725
遇见更好的自我
遇见更好的自我 2021-01-29 22:17

What is the advantage of using Condition interface/implementations over the conventional wait notify mechanism? Here I quote the comments written by Doug Lea:

5条回答
  •  孤城傲影
    2021-01-29 22:32

    In addition to other well accepted answers - since Condition is associated with Lock object you can have arbitrary sets of Lock objects (reawrite, read, write) in your class and have specific condition associated with that. Then you can use those set of condition to synchronize different parts of your class according to your implementation semantics. This gives more flexibility and explicit behavior then wait-notify imo

提交回复
热议问题