Java multithreading on producer-consumer
algorithm, java, multithreading
Solution
You could have any number of producers and any number of consumers.
If the producers produce too fast, the queue will fill up, until you get memory problems or the producers are forced to stay idle until there's some place left in the queue.
If the consumers consume too fast, they will stay idle most of the time.
Problem
I am following a video tutorial on Java multi-threading. It introduces on using Java to implement the famous "Producer-consumer" problem. It used wait() and notifyAll() to ensure the proper communication between producer threads and consumer threads. The tutor intentionally created several producer threads while only one consumer threads, but he left a question unanswered: "It is always best practice to have equal number of producer and consumer threads, if there are more producer threads than consumer, there will be problems". However, he didn't specify what that problem is. I personally imagine that would only be a situation that the basket is full. Could experts help here? Thanks.