当前位置:网站首页>Thread five states (thread life cycle)
Thread five states (thread life cycle)
2022-06-11 12:03:00 【java-zh】
There are four ways to create threads code : Four ways to create threads _java-zh The blog of -CSDN Blog
1、 New state
When the current object is created , Before starting ( There is no call start Method ), such as Thread t = new Thread();
2、 Ready state
Ready to start , It's not implemented , Express call start After method , Not obtained cpu resources
3、 Running state
Currently in progress to get cpu After resources
4、 Death state :
When the running thread executes all the code logic normally or the program ends due to abnormal conditions, it is called dead state
5、 Blocked state
While the program is running , Something happened , This causes the current thread to fail to execute smoothly , It's going to be blocked , Into a blocked state
After the cause is eliminated , All blocking queues It will enter the ready state again , Grab at random cpu resources , Waiting for execution
Be careful
Why we call start() Method run() Method , Why can't we call it directly run() Method ?
new One Thread, The thread has entered a new state . call start() Method , Starts a thread and puts it in a ready state , When it's assigned to a timeslice, it's ready to run . start() Will perform the corresponding preparatory work of the thread , And then automatically run() Contents of the method , This is real multithreading .
And direct execution run() Method , Will be able to run Method as one main Common methods under thread to execute , It does not execute in a thread , So it's not multithreading .
summary : call start Method to start a thread and make it ready , and run It's just thread A normal method call of , Or in the main thread .
边栏推荐
- [第二章 基因和染色体的关系]生物知识概括–高一生物
- 什么是Gerber文件?PCB电路板Gerber文件简介
- Zero after factorial (C language)
- Interview experience of Xiaomi Android development post~
- 普通人应当如何挑选年金险产品?
- 爱可可AI前沿推介(6.11)
- 让你理解选择排序(C语言)
- Elk - hearthbeat implements service monitoring
- MYCAT sub database and sub table
- 浙大联合微软亚研院发布视频识别新方法,可对视频逐帧识别且无需,数据标记,或可用于手语翻译等
猜你喜欢

ELK - ElastAlert最大的坑

01_ Description object_ Class diagram

Let you understand selection sorting (C language)

When I saw the sudden death of a 28 year old employee, I wanted to moisten

Maximum water container

C# 读取txt文件生成Word文档

Gestion de projets logiciels 7.1. Concept de base du calendrier du projet

中文输入法输入事件composition的使用

Streaking? Baa!

Zhejiang University and Microsoft Asia Research Institute released a new method of video recognition, which can recognize video frame by frame without data marking, or can be used for sign language tr
随机推荐
centos安装mysql5.7
ELK - ElastAlert最大的坑
Uncaught typeerror: cannot set property 'next' of undefined
2019 book list
The wonderful use of XOR (C language)
JS interview questions - arrow function, find and filter some and every
Web development model selection, who graduated from web development
AGCO AI frontier promotion (6.11)
Use of Chinese input method input event composition
Fast build elk7.3
Using fast and slow pointer method to solve the problem of array (C language)
ELK - X-Pack设置用户密码
采用快慢指针法来解决有关数组的问题(C语言)
反射真的很耗时吗,反射 10 万次,耗时多久。
InputStream读取文件OutputStream创建文件
[C language] anonymous/unnamed struct & Union
2020-07 study notes sorting
中国网络安全年会周鸿祎发言:360安全大脑构筑数据安全体系
Smart sidebar plug-in: Mo widgets
Learning in Bi design 03