Created
November 14, 2018 11:58
-
-
Save farmerjohngit/f9f611752db083116b6e4581c891ee9b to your computer and use it in GitHub Desktop.
This file contains 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
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