技术问答-26 线程的状态 新建 准备 运行 休眠 停止

package com.test;

public class Test {
	public static void main(String[] args) {
		//(1)新建
		Thread t = new Thread(new MyRunnablee());
		//(2)就绪 等待CPU
		t.start();
	}
}

class MyRunnablee implements Runnable{
	public void run() {
		//(3)开始执行
		System.out.println("运行状态开始");
		for(int i=0;i<10;i++) {
			try {
				//(4)休眠状态
				Thread.sleep(1000);
				System.out.println("执行run"+i);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		System.out.println("运行状态结束");
		//(5)执行完run之后 就结束状态了
	}
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-13
  • 2022-12-23
  • 2021-04-30
  • 2022-12-23
猜你喜欢
  • 2021-12-22
  • 2021-10-28
  • 2021-08-28
  • 2022-02-17
  • 2021-07-25
  • 2021-11-24
  • 2021-07-05
相关资源
相似解决方案