Created
May 4, 2011 01:46
-
-
Save hakanai/954607 to your computer and use it in GitHub Desktop.
Yet another thing that isn't really clear about thread safety
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class NotThreadSafe { | |
| private String value; | |
| public NotThreadSafe() { | |
| value = generateSomehow(); | |
| } | |
| public String getValue() { | |
| return value; | |
| } | |
| } | |
| // but what if I do this: | |
| final NotThreadSafe utility = new NotThreadSafe(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ThreadSafe { | |
| private final String value; | |
| public NotThreadSafe() { | |
| value = generateSomehow(); | |
| } | |
| public String getValue() { | |
| return value; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment