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);
}
}
线程锁
最新推荐文章于 2024-07-09 15:38:01 发布