当前位置:网站首页>线程的并行、并发、生命周期
线程的并行、并发、生命周期
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种状态的互相转换

边栏推荐
- Bao, what if the O & M 100+ server is a headache? Use Xingyun housekeeper!
- 6月刊 | AntDB数据库参与编写《数据库发展研究报告》 亮相信创产业榜单
- 华为云专家详解GaussDB(for MySQL)新特性
- Implement a Prometheus exporter
- Technical secrets of ByteDance data platform: implementation and optimization of complex query based on Clickhouse
- Solidity - 合约结构 - 错误(error)- ^0.8.4版本新增
- Mipi interface, DVP interface and CSI interface of camera [easy to understand]
- kubernetes命令入门(namespaces,pods)
- 11. Users, groups, and permissions (1)
- ECS summer money saving secret, this time @ old users come and take it away
猜你喜欢

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

Summary of the core steps in the life cycle of beans

B2B e-commerce platform solution for fresh food industry to improve the standardization and transparency of enterprise transaction process

2. Create your own NFT collections and publish a Web3 application to show them start and run your local environment

洞态在某互联⽹⾦融科技企业的最佳落地实践

机械设备行业数字化供应链集采平台解决方案:优化资源配置,实现降本增效

Chinese and English instructions human soluble advanced glycation end products receptor (sRAGE) ELISA Kit

Lake shore M91 fast hall measuring instrument

【pytorch记录】自动混合精度训练 torch.cuda.amp

宝,运维100+服务器很头疼怎么办?用行云管家!
随机推荐
Intensive cultivation of channels for joint development Fuxin and Weishi Jiajie held a new product training conference
前4A高管搞代运营,拿下一个IPO
Solution: you can ping others, but others can't ping me
寶,運維100+服務器很頭疼怎麼辦?用行雲管家!
数据仓库(四)之ETL开发
Viewing the whole ecology of Tiktok from a macro perspective
Altair HyperWorks 2022软件安装包和安装教程
Dlib+Opencv库实现疲劳检测
Gameframework eating guide
实现一个Prometheus exporter
Lumiprobe free radical analysis h2dcfda instructions
MySQL common graphics management tools | dark horse programmers
Altair HyperWorks 2022 software installation package and installation tutorial
【直播预约】数据库OBCP认证全面升级公开课
Graduation season | Huawei experts teach the interview secret: how to get a high paying offer from a large factory?
透过华为军团看科技之变(六):智慧公路
Boost the development of digital economy and consolidate the base of digital talents - the digital talent competition was successfully held in Kunming
Lake Shore M91快速霍尔测量仪
Solidity - 算术运算的截断模式(unchecked)与检查模式(checked)- 0.8.0新特性
Cdga | if you are engaged in the communication industry, you should get a data management certificate