Skip to content

Instantly share code, notes, and snippets.

@rinrinne
Last active August 9, 2017 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rinrinne/7e40638fba102d52b1d34a7b70b16b2d to your computer and use it in GitHub Desktop.
Save rinrinne/7e40638fba102d52b1d34a7b70b16b2d to your computer and use it in GitHub Desktop.
public class Main {
public static void main(String[] args) {
Runnable runnable = new Runnable() {
private Object obj = null;
@Override
public void run() {
displayHash();
}
private void displayHash() {
if (obj == null) {
obj = new Object();
}
System.out.println(obj.hashCode());
}
};
for (int i = 0; i < 5; i++) {
Thread thread = new Thread(runnable);
thread.start();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment