<---------------线程修改名字、得到名字及开启------------------>
作者:互联网
ThreadDemo: public class ThreadDemo extends Thread { public void run(){ System.out.println(getName());//得到线程名字 // System.out.println(0/0); for (int i = 0; i < 50; i++) { System.out.println("run里的。。。。"+i); } } }
TestThreadDemo: public class TestThreadDemo { public static void main(String[] args) { ThreadDemo th = new ThreadDemo(); th.setName("旺财");//修改线程名字 //th.run(); th.start();//run开启线程 fun1(); //获得正在运行线程的名字 // Thread cur = Thread.currentThread(); // String name = cur.getName(); // System.out.println(name); String name = Thread.currentThread().getName(); } public static void fun1(){ for (int j = 0; j <5000; j++) { System.out.println("main..."+j); } } }
标签:,run,ThreadDemo,System,th,public,out 来源: https://www.cnblogs.com/duguangming/p/10554757.html