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 ...

Get Special Edition Using Java 2 Standard Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.