Skip to content

Instantly share code, notes, and snippets.

@farmerjohngit
Created November 14, 2018 11:58
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 farmerjohngit/f9f611752db083116b6e4581c891ee9b to your computer and use it in GitHub Desktop.
Save farmerjohngit/f9f611752db083116b6e4581c891ee9b to your computer and use it in GitHub Desktop.
public class Test {
class MyLock {
}
final Object lock = new MyLock();
public static void main(String[] args) {
new Test().test();
}
public void test() {
new Thread(new Runnable() {
@Override
public void run() {
System.out.println("1. get lock prepare");
synchronized (lock) {
System.out.println("1. get lock success");
}
new CustomThread().start();
}
}).start();
}
class CustomThread extends Thread {
@Override
public void run() {
synchronized (lock) {
System.out.println("2. get lock success");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment