标签:new t nbsp rgs ide out ace current not auto
子线程循环10次,接着主线程循环100次,接着又回到子线程循环10次,接着再回到主线程循环100次,如此循环50次
public class Sub10Main100Loop50Thread {
public static void main(String[] args) throws InterruptedException {
Business business = new Business();
new Thread(new Runnable(){
@Override
public void run() {
for(int i=0;i<5;i++){
business.sub(i);
}
}
}){}.start();
Thread.sleep(1000);//目的是让子线程先跑
for(int i=0;i<50;i++){
business.main(i);
}
}
}
class Business{
public synchronized void sub(int i){
for(int j=0;j<10;j++){
System.out.println(Thread.currentThread().getName()+ " "+j);
}
this.notify();
try {
this.wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public synchronized void main(int i){
for(int j=0;j<100;j++){
System.out.println(Thread.currentThread().getName()+ " "+j);
}
this.notify();
try {
this.wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
参考:http://blog.csdn.net/xiaoyu714543065/article/details/8257394
子线程循环10次,接着主线程循环100次,接着又回到子线程循环10次,接着再回到主线程循环100次,如此循环50次-004
标签:new t nbsp rgs ide out ace current not auto
原文地址:http://www.cnblogs.com/ysloong/p/6370104.html