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()); } }
初级程序员
by: 简明 发表于:2017-11-27 16:38:29 顶(0) | 踩(0) 回复
谢谢分享,好好学习
回复评论