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

Missing volatile keyword #44

Open
vskishan opened this issue Oct 14, 2024 · 0 comments
Open

Missing volatile keyword #44

vskishan opened this issue Oct 14, 2024 · 0 comments

Comments

@vskishan
Copy link

vskishan commented Oct 14, 2024

From the class ThreadSafeSingleton.java at path design-patterns/java/singleton/ThreadSafeSingleton.java

I could see that the below statement is missing the volatile keyword.

private static ThreadSafeSingleton instance;

Although we are breaking the contention using synchronized method, ongoing threads that try to access this method might still see that instance == null even after it has been instantiated.

CC : @ashishps1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant