This week's book giveaways are in the iOS and Features new in Java 8 forums. We're giving away four copies each of Barcodes with iOS: Bringing together the digital and physical worlds and Core Java for the Impatient and have the authors on-line! See this thread and this one for details.
I am learning thread synchronization and working on producer/consumer problem. Although, I am using jdk 1.5 but for simplicity, I am avoiding using ExecutorService and BlockingQueue and just trying to concentrate on thread synchronization. There are 3 producers and 4 consumers that communicate among themselves via a queue.
Here is my code:
Upon running this code, I get the following exceptions in my eclipse console:
Now, look at your Buffer.get() method. It's marked as synchronized, which means it's synchronized on the Buffer object. But then you call producerLock.wait(). So you need to either change the object you're synchronizing on, or change the object you're calling wait/notify on.