-
Notifications
You must be signed in to change notification settings - Fork 0
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
Singleton is not thread safe #1
Comments
To be more precisely - if you try access your singleton from more than one thread you can create more than one instance of your singleton: Let's try this slightly modified code: `
} For most of the time my output is OK: First there is a message "Creating new instance", then "New instance created", and all objects have the same hashcode. But, sometimes, output is like: As you can see, one of the threads created his own instance - this can lead to very unexcpected behaviours. |
yes you are right |
Hello. In your readme there is:
But your Singleton-class is not thread safe.
The text was updated successfully, but these errors were encountered: