Skip to content

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

Open
@ad-kmt

Description

@ad-kmt

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    on-jiratriagedIssues reviewed by a dev and considered valid. Will be added in Jira.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions