public class QueuePrint { public int targetNum=0; //输出的总数量 public int printOnce=0; //当前次数输出数量 private int nowNum=1; //要打印的数量 /** * * @param targetNum 输出的总数量 * @param printOnce 当前次数输出数量 */ public QueuePrint(int targetNum, int printOnce) { super(); this.targetNum = targetNum; this.printOnce = printOnce;
}
private int nextThreadNum=0;//next的下标数 private int threadCount=0;//总的线程数量 //map集合,存放线程,键是具体线程,值存放线程打印的顺序 private Map<Thread,Integer> threads=new LinkedHashMap<Thread,Integer>();
//添加线程 public void setTh(Thread thread) { threads.put(thread, threadCount); threadCount++;
} //运行线程 public void run() { for (Thread thread : threads.keySet()) {
thread.start();
}
}