Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ad-kmt opened this issue Mar 17, 2024 · 0 comments
Open

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

ad-kmt opened this issue Mar 17, 2024 · 0 comments
Labels
on-jira triaged Issues reviewed by a dev and considered valid. Will be added in Jira.

Comments

@ad-kmt
Copy link

ad-kmt commented Mar 17, 2024

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

@apeterlic apeterlic added the triaged Issues reviewed by a dev and considered valid. Will be added in Jira. label Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
on-jira triaged Issues reviewed by a dev and considered valid. Will be added in Jira.
Projects
None yet
Development

No branches or pull requests

3 participants