62,635
社区成员




public class TestThread11 {
private static Object lock = new Object();
public void execute(){ // synchronized修饰
synchronized(lock){
for (int i = 0; i < 10; i++) {
System.out.println(Thread.currentThread().getName()+":"+i);
if(i == 5){
try {
lock.wait();
System.out.println(Thread.currentThread().getName());
} catch (InterruptedException e) {
e.printStackTrace();
}
}
lock.notify();
}
}
}
}
class ThreadAA implements Runnable {
public void run() {
TestThread11 test = new TestThread11();
test.execute();
}
public static void main(String[] args)
{
Runnable runabble=new ThreadAA();
Thread a=new Thread(runabble,"A");
a.start();
Thread b=new Thread(runabble,"B");
b.start();
Thread c=new Thread(runabble,"C");
c.start();
}
}