package com.sunday.nineone;
import java.util.Date;
import com.wjl.util.DateUtilsEx;
public class Test {
private static String[] t_start = {"A","B","C","A","C","B",""};
private static int i = 0;
public static void main(String[] args) {
Thread tha = new Thread(new Task(),"A");
Thread thb = new Thread(new Task(),"B");
Thread thc = new Thread(new Task(),"C");
tha.start();
thb.start();
thc.start();
}
public static class Task extends Thread{
@Override
public void run() {
while(Test.i < Test.t_start.length){
String name=Thread.currentThread().getName();
if(Test.t_start[Test.i].equals(name)){
System.out.println(name+"线程 当前时间是:"+DateUtilsEx.FORMAT_ISO_DATE_TIME().format(new Date()));
Test.i ++;
}else if(Test.t_start[Test.i].equals(name)){
System.out.println(name+"线程 当前时间是:"+DateUtilsEx.FORMAT_ISO_DATE_TIME().format(new Date()));
Test.i ++;
}else if(Test.t_start[Test.i].equals(name)){
System.out.println(name+"线程 当前时间是:"+DateUtilsEx.FORMAT_ISO_DATE_TIME().format(new Date()));
Test.i ++;
}
}
}
}
}
评论0
最新资源