eugenp / tutorials

Just Announced - "Learn Spring Security OAuth":

Home Page:http://bit.ly/github-lsso

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Thread Safety Issue in DataQueue add() and poll() Methods

ad-kmt opened this issue · comments

https://github.com/eugenp/tutorials/blob/35dcd94d8a68d98af8e770ca122c07047adbdc86/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/producerconsumer/DataQueue.java

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