Synchronizing this statement should block the second thread from accessing the queue correct?
No, because your code synchronizes on this
inside the ProductConsumer
class which means the current instance of the ProductConsumer
object. Since each thread has a different ProductConsumer
instance, it doesn't prevent the threads from adding items to the queue concurrently. It would be a different thing if you synchronized on the queue though.
I would personally recommend starting with the Java trail and working through the concepts incrementally instead of continuing down this path of haphazard changes. :)