Single stream notification: notify, notify about everything or at the same time.

I need to wake up or send a single topic to sleep sometimes, and I wonder what is the best and most effective way to do this.

The first solution signals in combination with wait-notify(I know how to correctly implement this template, this is not a question).

I read it somewhere that using the java.concurrent library and CountDownLatchfor signaling is more efficient. I also checked concurrent.locks.Condition , but this one indicates that it is just (a programmer) a more secure and generalized construct without increasing performance compared to notify/notifyAll. Peter Lowry recommends using the Concurrency library instead notify-notifyAllof this comment, so now I'm confused what is best to use.

A related question: what is better in performance, notifyor notifyAllin my case (i.e. if I have one thread)? I know that there are many similar topics, but none of them give a clear answer. In my case, functionally, it doesn't matter what I use, but I wonder what is faster.

+5
source share
2 answers

IMO " ", , wait, , , . ? /, , - , , -, .

, , , , , - .

+3

wait-notify .

, notify notifyAll , .

0

All Articles