package thread.name;
import java.text.SimpleDateFormat;
import java.util.Date;
public class GetThreadName implements Runnable {
//private int i=10;
private boolean flag = true;
@Override
public void run() {
while(flag){
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(Thread.currentThread().getName());
System.out.println("================");
}
}
public void stop(){
this.flag = false;
}
}
public class ThreadMain {
/**
* @param args
* @throws InterruptedException
*/
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
GetThreadName test = new GetThreadName();
Thread proxy1 = new Thread(test,"test1");
proxy1.start();
System.out.println(Thread.currentThread().getName()+"-proxy1-");
System.out.println("====================");
System.out.println(Thread.currentThread().getName()+"-main-");
System.out.println("====================");
test.stop();
System.out.println(Thread.currentThread().getName());
}
}
为什么输出是
main-proxy1-
====================
main-main-
====================
main
test1
================
这段代码中线程的执行顺序是? 为什么最后一个main出现在test1 上面?
波斯汪
素胚勾勒不出你
胡说叔叔
相关分类