当前位置:网站首页>线程的并行、并发、生命周期
线程的并行、并发、生命周期
2022-07-01 18:43:00 【斯文~】
本文仅作简单记录,更专业内容建议阅读操作系统中有关线程、进程的知识。
并发与并行
正在运行的程序(软件)就是一个独立的进程, 线程是属于进程的,多个线程其实是并发与并行同时进行的。
并发的理解
1.CPU同时处理线程的数量有限;
2.CPU会轮询为系统的每个线程服务,由于CPU切换的速度很快,给我们的感觉这些线程在同时执行,这就是并发。
并行的理解
在同一个时刻上,同时有多个线程在被CPU处理并执行。
线程的声明周期
线程的状态
也就是线程从生到死的过程,以及中间经历的各种状态及状态转换,理解线程的状态有利于提升并发编程的理解能力。
Java线程的状态
Java总共定义了6种状态,定义在Thread类的内部枚举类中。
public enum State {
NEW,
RUNNABLE,
BLOCKED,
WAITING,
TIMED_WAITING,
TERMINATED;
}
| 状态 | 说明 |
|---|---|
| NEW(新建) | 线程刚被创建,但是并未启动 |
| Runnable(可运行) | 线程已经调用了start()等待CPU调度 |
| Blocked(锁阻塞) | 线程在执行的时候未竞争到锁对象,则该线程进入Blocked状态 |
| Waiting(无限等待) | 一个线程进入Waiting状态,另一个线程调用notify或者notifyAll方法才能够唤醒 |
| Timed Waiting(计时等待) | 同waiting状态,有几个方法有超时参数,调用他们将进入Timed Waiting状态。带有超时参数的常用方法有Thread.sleep 、Object.wait |
| Teminated(被终止) |

知识链接:Java线程通信
线程的6种状态的互相转换

边栏推荐
- Digital business cloud: from planning to implementation, how does Minmetals Group quickly build a new pattern of digital development?
- Supervarimag superconducting magnet system SVM series
- Excel之VBA简单宏编程
- Clean up system cache and free memory under Linux
- 【AGC】如何解决事件分析数据本地和AGC面板中显示不一致的问题?
- Superoptimag superconducting magnet system - SOM, Som2 series
- Summary of the core steps in the life cycle of beans
- PriorityQueue的用法和底层实现原理
- 【Go ~ 0到1 】 第五天 7月1 类型别名,自定义类型,接口,包与初始化函数
- Boost the development of digital economy and consolidate the base of digital talents - the digital talent competition was successfully held in Kunming
猜你喜欢

Lumiprobe phosphide hexaethylene phosphide specification

CDGA|从事通信行业,那你应该考个数据管理证书

How to realize the applet in its own app to realize continuous live broadcast

Clean up system cache and free memory under Linux

Bao, what if the O & M 100+ server is a headache? Use Xingyun housekeeper!

【快应用】text组件里的文字很多,旁边的div样式会被拉伸如何解决

Games202 operation 0 - environment building process & solving problems encountered

Prices of Apple products rose across the board in Japan, with iphone13 up 19%

Solution of intelligent supply chain management platform in aquatic industry: support the digitalization of enterprise supply chain and improve enterprise management efficiency

精耕渠道共谋发展 福昕携手伟仕佳杰开展新产品培训大会
随机推荐
2020, the regular expression for mobile phone verification of the latest mobile phone number is continuously updated
案例分享:QinQ基本组网配置
Viewing the whole ecology of Tiktok from a macro perspective
Go语言高级
kubernetes命令入门(namespaces,pods)
Dom4J解析XML、Xpath检索XML
【AGC】如何解决事件分析数据本地和AGC面板中显示不一致的问题?
Golang error handling
Lumiprobe 自由基分析丨H2DCFDA说明书
Summary of the core steps in the life cycle of beans
【Go ~ 0到1 】 第四天 6月30 defer,结构体,方法
实例讲解将Graph Explorer搬上JupyterLab
3. "Create your own NFT collections and publish a Web3 application to show them" cast NFT locally
如何使用物联网低代码平台进行个人设置?
精益思想:来源,支柱,落地。看了这篇文章就懂了
Three simple methods of ES6 array de duplication
Solution of digital supply chain centralized purchase platform in mechanical equipment industry: optimize resource allocation and realize cost reduction and efficiency increase
AppGallery Connect场景化开发实战—图片存储分享
记一次 .NET 差旅管理后台 CPU 爆高分析
学习笔记-JDBC连接数据库操作的步骤