标签:执行 interrupt 分享图片 override star set trace 注释 pac
一.线程状态的切换
5种
二.深入理解run()和start()
run方法就是普通对象的普通方法,只有调用了start()后,Java才会将线程对象和操作系统中实际的线程进行映射,再来执行run方法
package concurrent; /** * start()和run()的区别 */ public class StartAndRun { public static class ThreadRun extends Thread{ @Override public void run() { int i = 90; while(i>0){ try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("I am "+Thread.currentThread().getName() +" and now the i="+i--); } } } public static void main(String[] args) { ThreadRun beCalled = new ThreadRun(); beCalled.setName("BeCalled"); beCalled.run(); //beCalled.start(); } }
运行结果:
放开start(),注释run()之后:
标签:执行 interrupt 分享图片 override star set trace 注释 pac
原文地址:https://www.cnblogs.com/lingluo2017/p/10274873.html