O'Reilly logo

Special Edition Using Java 2 Standard Edition by Geoff Friesen, Chuck Cavaness, Brian Keeton

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

Thread Synchronization

Up to this point in the discussion, the threads haven't needed to interact with other threads. However, there are many cases in which threads need to work together to perform a larger task. For example, if you have two threads, one is creating or "producing" data and the other thread needs to read or "consume" that data. This problem is commonly known as the producer/consumer problem. One thread is the producer of the data and the second thread is considered the consumer. As you learned previously, there is no guarantee which thread will be running at any given instance of time. In fact, the producer thread can be right in the middle of creating some data and be interrupted by the consumer thread. What would the data look ...

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