javabufferconsumerproducer

How to solve a "1 producer 2 consumers" problem in java


I am pretty new in writing Java and i'm currently trying to implement a different aspect of the classic "Producer-Consumer" problem. I still use one Producer like usual, who writes strings in a buffer. This buffer is shared with the 2 Consumer threads, and what I am trying to do is to have both the Consumers pick up EVERY string the producer sends, and ONLY then delete the string from the buffer. How can i check if both the Consumer threads have already taken the string??? Thank you!


Solution

  • Maybe you can use the observer pattern.

    More info: https://www.baeldung.com/java-observer-pattern