Java源代码:
public class SimpleThread extends Thread{
int index; //线程编号
public SimpleThread(int index){
this.index = index;
System.out.println("Create Thread[" + index + "]");
}
//在线程中定义运行代码
@Override
public void run(){
//循环打印当前次数
for(int j = 0; j <=3; j++){
System.out.println("Thread[" + index + "]:running time "+j);
}
//当前线程运行结束
System.out.println("Thread[" + index +"] finish");
}
public static void main(String[] args){
for(int j = 0; j < 3; j ++){
Thread t = new SimpleThread(j + 1);
t.start();
}
}
}