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

边栏推荐
- 制造业SRM管理系统供应商全方位闭环管理,实现采购寻源与流程高效协同
- Cache problems after app release
- Summary of cases of players' disconnection and reconnection in Huawei online battle service
- Solidity - 合约结构 - 错误(error)- ^0.8.4版本新增
- Excel之VBA简单宏编程
- 水产行业智能供应链管理平台解决方案:支撑企业供应链数字化,提升企业管理效益
- Viewing the whole ecology of Tiktok from a macro perspective
- [quick application] win7 system cannot run and debug projects using Huawei ide
- Usage and underlying implementation principle of PriorityQueue
- Manufacturing SRM management system supplier all-round closed-loop management, to achieve procurement sourcing and process efficient collaboration
猜你喜欢

Lake shore M91 fast hall measuring instrument

寶,運維100+服務器很頭疼怎麼辦?用行雲管家!

Is PMP cancelled??

透过华为军团看科技之变(六):智慧公路

Solidity - 合约结构 - 错误(error)- ^0.8.4版本新增

Intensive cultivation of channels for joint development Fuxin and Weishi Jiajie held a new product training conference

MySQL common graphics management tools | dark horse programmers

Lumiprobe 自由基分析丨H2DCFDA说明书

The former 4A executives engaged in agent operation and won an IPO

Huawei cloud experts explain the new features of gaussdb (for MySQL)
随机推荐
Openai video pre training (VPT): action learning based on watching unmarked online videos
精益思想:来源,支柱,落地。看了这篇文章就懂了
lefse分析
Team up to learn! 14 days of Hongmeng equipment development "learning, practicing and testing" practical camp, free of charge!
Huawei game failed to initialize init with error code 907135000
Golang error handling
Qfile read / write file operation in QT
bean的生命周期核心步骤总结
[6.24-7.1] review of wonderful technical blog posts in the writing community
Redis 实现限流的三种方式
Summary of the core steps in the life cycle of beans
从零开始学 MySQL —数据库和数据表操作
【AGC】如何解决事件分析数据本地和AGC面板中显示不一致的问题?
ETL development of data warehouse (IV)
Appgallery connect scenario development practice - image storage and sharing
ES6 summary "suggestions collection" of array methods find(), findindex()
记一次 .NET 差旅管理后台 CPU 爆高分析
宝,运维100+服务器很头疼怎么办?用行云管家!
PriorityQueue的用法和底层实现原理
Create your own NFT collections and publish a Web3 application to show them (Introduction)