O'Reilly logo

Java 9 Concurrency Cookbook - Second Edition by Javier Fernández González

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

The key to this example is the set() and get() methods of the EventStorage class. First of all, the set() method checks whether there is free space in the storage attribute. If it's full, it calls the wait() method to wait for free space. When the other thread calls the notify() method, this thread wakes up and checks the condition again. The notify() method doesn't guarantee that the condition is met. This process is repeated until there is free space in storage and it can generate a new event and store it.

The behavior of the get() method is similar. First, it checks whether there are events on the storage attribute. If the EventStorage class is empty, it calls the wait() method to wait for events. When the other thread ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required