package thread.name;import java.text.SimpleDateFormat;import java.util.Date;public class GetThreadName implements Runnable {//private int i=10;private boolean flag = true;@Overridepublic 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-====================maintest1================这段代码中线程的执行顺序是? 为什么最后一个main出现在test1 上面?
3 回答
添加回答
举报
0/150
提交
取消