Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Events
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
JavaDevelopRep
Java
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
Java
/
day23
/
day23总结.txt
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
64 lines (63 loc) · 1.41 KB
master
Breadcrumbs
Java
/
day23
/
day23总结.txt
Copy path
Top
File metadata and controls
Code
Blame
64 lines (63 loc) · 1.41 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
1:多线程(理解)
(1)多进程
进程:正在执行的应用程序。
多进程的意义?
提高了CPU的使用率
(2)多线程
线程:进程的执行路径,执行单元。
多线程的意义?
提高了应用程序的使用率
随机性原理:
因为多个线程不断去抢CPU的资源,CPU就在这多个线程间进行快速的切换,造成了随机性。
(3)并行和并发
并行:逻辑上同时,同一个时间内
并发:物理上同时,同一个时间点
(4)多线程的实现方案(自己补齐实现步骤和代码)
A:继承Thread类
B:实现Runnable接口
(5)常见的几个小问题
A:为什么要重写run()方法
B:启动线程使用的是哪个方法
C:start()和run()方法的区别
D:一个线程能不能启动多次
E:有了继承Thread类实现,为什么还要有实现接口的实现
F:生命周期
(6)线程的调度
线程调度:
A:分时调度
B:抢占式调度
java采用第二种方案。
获取和设置线程的优先级。
默认优先级是5
优先级范围是1-10
(7)线程的控制
A:线程休眠
B:线程加入
C:线程礼让
D:守护线程
E:中断线程
(8)生命周期图(看懂,最好能够自己画)
(9)通过多线程模拟电影院卖票
A:继承Thread类
B:实现Runnable接口
(10)通过多线程模拟电影院卖票(加入延迟)
A:相同的票卖多次
CPU的一次执行必须是原子性操作
B:出现了负数的票
线程的随机性和延迟
(11)线程安全问题是如何产生的呢?
A:多线程环境
B:有共享数据
C:多条语句操作共享数据
(12)解决方案:
A:同步代码块
格式:
synchronized(对象) {
需要被同步的代码
}
对象可以是任意对象
B:同步方法
非静态 对象是this
静态 对象是当前类的字节码文件对象
(13)查看以前学习的几个类的源码
StringBuffer,Vector,Hashtable
You can’t perform that action at this time.