Thread Safety Issue in DataQueue add() and poll() Methods
Author: ad-kmtCreated Mar 17, 2024Updated Mar 29, 2024
Labelstriagedon-jira
The DataQueue class in the Producer-Consumer implementation uses a LinkedList to implement the queue, which is not thread-safe. Additionally, the add() and poll() methods of DataQueue are not synchronized. I feel this can lead to race conditions, data corruption, and visibility issues when multiple threads concurrently access the queue.
Kindly correct me if I'm wrong, Thanks!
Article: https://www.baeldung.com/java-producer-consumer-problem
Source: eugenp/tutorials