import java.util.concurrent.atomic.AtomicInteger;
/**
* @author zerodsLyn
* created on 2020/5/10
*/
public class MultiThreadSerialPrint {
private final Thread[] threads;
/**
* 打印线程数目
*/
final int threadNum;
AtomicInteger num;
private final int end;
/**
* 打印任务是否结束
*/
volatile boolean running = true;
public ThreadPrint(int threadNum, int end) {
this.num = new AtomicInteger(0);
this.end = end;
this.threadNum = threadNum;
this.threads = new Thread[threadNum];
for (int i = 0; i < threadNum; i++) {
Thread thread = new Thread(new PrintTask(this), "thread-" + i);
threads[i] = thread;
}
}
public void run() {
for (Thread thr