当前位置:网站首页>线程的并行、并发、生命周期
线程的并行、并发、生命周期
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种状态的互相转换
边栏推荐
- Openai video pre training (VPT): action learning based on watching unmarked online videos
- The best landing practice of cave state in an Internet ⽹⾦ financial technology enterprise
- PostgreSQL varchar[] 数组类型操作
- Three ways for redis to realize current limiting
- Three simple methods of ES6 array de duplication
- Lake Shore—CRX-EM-HF 型低温探针台
- Viewing technological changes through Huawei Corps (VI): smart highway
- 11. Users, groups, and permissions (1)
- [6.24-7.1] review of wonderful technical blog posts in the writing community
- Stanford, salesforce|maskvit: masked vision pre training for video prediction
猜你喜欢
nacos配置文件发布失败,请检查参数是否正确的解决方案
Docker deploy mysql8.0
毕业季 | 华为专家亲授面试秘诀:如何拿到大厂高薪offer?
MATLAB中subplot函数的使用
Graduation season | Huawei experts teach the interview secret: how to get a high paying offer from a large factory?
B2B e-commerce platform solution for fresh food industry to improve the standardization and transparency of enterprise transaction process
宝,运维100+服务器很头疼怎么办?用行云管家!
制造业SRM管理系统供应商全方位闭环管理,实现采购寻源与流程高效协同
洞态在某互联⽹⾦融科技企业的最佳落地实践
Altair HyperWorks 2022软件安装包和安装教程
随机推荐
The best landing practice of cave state in an Internet ⽹⾦ financial technology enterprise
实例讲解将Graph Explorer搬上JupyterLab
Taiaisu M source code construction, peak store app premium consignment source code sharing
实现一个Prometheus exporter
Netease games, radical going to sea
水产行业智能供应链管理平台解决方案:支撑企业供应链数字化,提升企业管理效益
【pytorch记录】自动混合精度训练 torch.cuda.amp
[6.24-7.1] review of wonderful technical blog posts in the writing community
Create your own NFT collections and publish a Web3 application to show them (Introduction)
11. Users, groups, and permissions (1)
Dlib+Opencv库实现疲劳检测
太爱速M源码搭建,巅峰小店APP溢价寄卖源码分享
数据仓库(四)之ETL开发
PriorityQueue的用法和底层实现原理
华为联机对战服务玩家掉线重连案例总结
CDGA|从事通信行业,那你应该考个数据管理证书
XML语法、约束
Summary of cases of players' disconnection and reconnection in Huawei online battle service
[quick application] win7 system cannot run and debug projects using Huawei ide
indexof和includes的区别