多线程顺序执行(为了提高效率,又不可以打乱执行顺序)
public class MultiThreadInSequence extends Thread{
public static int max=999;
public static int count=0;
public void run() {
if(MultiThreadInSequence.count<MultiThreadInSequence.max)
MultiThreadInSequence.count++;
System.out.print(count);
}
}
/*{//mian方法
MultiThreadInSequence []thread=new MultiThreadInSequence[20];
for(int k=0;k<20;k++) {
thread[k]=new MultiThreadInSequence();
}
while(MultiThreadInSequence.count<MultiThreadInSequence.max) {
for(int i=0;i<20;i++) {
thread[i].run();
try {
thread[i].join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
*/