62,635
社区成员




public class ThreadB {
public static void main(String[] args) {
for (int i = 0; i < 100; i++) {
Thread t = new Thread(new MyRunnable());
t.start();
}
synchronized ("hello") {
try {
"hello".wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
//继续做主线程的业务
for (int i = 0; i < 1000; i++) {
System.out.println("main----->" + i);
}
}
}
class MyRunnable implements Runnable {
@Override
public void run() {
synchronized ("hello") {
for (int i = 1; i <= 1000; i++) {
System.out.println(Thread.currentThread().getName() + "------>"
+ i);
"hello".notify();
}
}
}
}