Skip to content

Instantly share code, notes, and snippets.

@hakanai
Created May 4, 2011 01:46
Show Gist options
  • Select an option

  • Save hakanai/954607 to your computer and use it in GitHub Desktop.

Select an option

Save hakanai/954607 to your computer and use it in GitHub Desktop.
Yet another thing that isn't really clear about thread safety
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();
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