package test; public class Test0919 { public static void main(String args[]) { A a=new A("t1"); } } class A implements Runnable { Thread t=null; String tname=null; public A(String tname) { this.tname=tname; this.t=new Thread(this, tname); this.t.start(); } @Override public void run() { try { for(int i=0;i<20;i++) { System.out.println(this.t.getName()); this.t.sleep(300); } } catch (InterruptedException e) { e.printStackTrace(); } } }
为什么将A类中构造方法中线程的构造方法改为thread(tname)控制台就不打印线程名称啦
package test; public class Test0919 { public static void main(String args[]) { A a=new A("t1"); } } class A implements Runnable { Thread t=null; String tname=null; public A(String tname) { this.tname=tname; this.t=new Thread(tname); this.t.start(); } @Override public void run() { try { for(int i=0;i<20;i++) { System.out.println(this.t.getName()); this.t.sleep(300); } } catch (InterruptedException e) { e.printStackTrace(); } } }
慕的地8271018
慕哥9229398
相关分类