本文共 904 字,大约阅读时间需要 3 分钟。
1、多线程按规定顺序输出
package test;import java.util.HashSet;import java.util.Set;public class Main12 { public static void main(String[] args) { String[] strs={"_A","_B","_C"}; Thread pre=Thread.currentThread(); for(int i=0;i<3;i++){ Thread thread=new Thread(new Domio(strs[i],pre)); thread.start(); pre=thread; } System.out.print("begin"); } static class Domio implements Runnable{ private String str; private Thread thread; public Domio(String str,Thread thread){ this.str=str; this.thread=thread; } @Override public void run() { String string=this.str; try { this.thread.join(); } catch (InterruptedException e) { e.printStackTrace(); } System.out.print(str); } }}输出:begin_A_B_C
转载地址:http://zgpqb.baihongyu.com/