What happens if I call a notification in a thread that is not waiting?

I want to have a thread that sits on top of the event queue and responds to it accordingly. My idea was to clear all the elements, and as soon as it reaches the end of the queue, press wait()until something is there notify(). However, the question arises, what happens when it notify()happens, when the thread is not waiting?

PS: What is this monitor business that I read in javadoc?

+3
source share
3 answers

The short answer is that nothing happens.

, , , , .

monitor, , - . (IIRC - , concurrency.)

, ( Java, ), , . , , , . wait notify , .

+6

, - wait(), notify(). , , , , .

, notify() , , notify() . , wait(), .

+4

In response to your PS, monitors are one of the main concurrency primitives. There are several different flavors of which Java uses the wait and notify option. All of this is well explained in a Wikipedia article:

http://en.wikipedia.org/wiki/Monitor_ (sync)

+1
source

Source: https://habr.com/ru/post/1795131/


All Articles