概述
- 进程:程序的一次运行,操作系统分配内存资源和调度的基本的单位;有独立的内存地址;一个程序至少有一个进程;
- 线程:最小的执行单元,CPU 调度的单位;由线程ID、程序计数器、寄存器集合和栈组成;一个进程至少有一个线程,多个线程之间共享一段内存,且可并发执行
进程状态
- 就绪
- 执行
- 阻塞
线程间共享变量
- 互斥锁
- 信号量
CPU 调度
- 先到先服务调度(FIFS)
- 最短作业优先调度(SJF)
- 优先权调度
- 轮转法调度(RR)
- 多级队列调度
- 多级反馈队列调度
问答
When is a Java thread alive?
According to the Javadoc you mentionned:
A thread is alive if it has been started and has not yet died.
A thread "starts" when its start()
method is invoked and "dies" at the end of its run()
method, or when stop()
(now deprecated) is invoked. So yes, a thread is "alive" when its run()
method is still ongoing, but it is also "alive" in the time window between the invocation of start()
and the implicit invocation of the run()
method by the JVM.