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

[QUERY] Volatile Example #16722

Open
DivyaSaravanan opened this issue May 25, 2024 · 0 comments
Open

[QUERY] Volatile Example #16722

DivyaSaravanan opened this issue May 25, 2024 · 0 comments
Labels
on-jira triaged Issues reviewed by a dev and considered valid. Will be added in Jira.

Comments

@DivyaSaravanan
Copy link

DivyaSaravanan commented May 25, 2024

Article and Module Links
Guide to the Volatile Keyword in Java.

Describe the Issue

The volatile example provided works fine, even without adding volatile keyword.

https://github.com/eugenp/tutorials/blob/master/core-java-modules/core-java-concurrency-simple/src/main/java/com/baeldung/concurrent/volatilekeyword/TaskRunner.java#L6

To Reproduce
Steps to reproduce the behavior:

  • Go to Task Runner

  • Remove the Volatile keyword next to the field ready.

  • Execute the code, still, the code works fine.

Expected Behavior
If the volatile keyword is not present, ideally the reader thread and main thread would have local copies of the ready variable, and the while loop would not exit.

Does the above vary in cases, and not always expected?

Screenshots
If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

  • OS: [e.g. Windows]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Additional Context
Add any other context about the issue here.

@DivyaSaravanan DivyaSaravanan changed the title [ISSUE] Volatile Example [QUERY] Volatile Example May 25, 2024
@apeterlic apeterlic added the triaged Issues reviewed by a dev and considered valid. Will be added in Jira. label Jun 5, 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