一. 线程状态的切换
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() 之后:
来源: http://www.bubuko.com/infodetail-2922151.html