public class Test extends Thread { public void run() { printMsg(); } public void printMsg() { // 获得运行此代码的线程的引用 Thread t = Thread.currentThread(); String name = t.getName(); System.out.println("name = " + name); } public static void main(String[] args) { Test t = new Test(); t.setName("MyThread"); System.out.println("线程状态 = " + t.isAlive()); t.start(); System.out.println("线程已启动..."); System.out.println("线程状态 = " + t.isAlive()); } }
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/10353.html