public class test {
public static void main(String[] args) throws Throwable {
C c = new C();
Thread t = new Thread(()->c.a());
t.start();
Thread t2 = new Thread(()->c.b());
t2.start();
Thread t3 = new Thread(()->c.c());
t3.start();
}
}
class C{
synchronized void a() {
System.out.println(1);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(2);
}
synchronized void b() {
System.out.println(3);
}
void c() {
System.out.println(4);
}
}
線程鎖
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.