public class DeadThread {
A a = new A();
B b = new B();
public DeadThread() {
a.start();
b.start();
}
public static void main(String[] args) {
new DeadThread();
}
class A extends Thread {
@Override
public void run() {
getKZ();
}
public synchronized void getKZ() {
try {
System.out.println("我有筷子,我想要勺子");
Thread.sleep(1000);
b.getSZ();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
class B extends Thread {
@Override
public void run() {
getSZ();
}
public synchronized void getSZ() {
try {
System.out.println("我有勺子,我想要筷子");
Thread.sleep(1000);
a.getKZ();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}