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
/
day24
/
day24总结.txt
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
79 lines (71 loc) · 1.25 KB
master
Breadcrumbs
Java
/
day24
/
day24总结.txt
Copy path
Top
File metadata and controls
Code
Blame
79 lines (71 loc) · 1.25 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
1:多线程(理解)
(1)JDK5的Lock锁
A:lock()
B:unlock()
(2)死锁代码
代码要看一遍。
(3)线程间的通信问题
A:基本的代码实现
B:解决了线程安全问题的代码
C:等待唤醒机制的代码
D:通过同步方法改进版的代码
(4)线程组
ThreadGroup
(5)线程池
...
Executors
方法:future<> newFixedThreadPool()
(6)多线程方式3
实现Callable接口
好处:
A:返回值
B:可以抛异常
弊端:
代码比较麻烦
案例:
求和
(7)定时器
Timer
TimerTask
2:单例设计模式(理解)
(1)保证类在内存中只有一个对象
(2)如何实现的?
A:构造私有
B:自己提供对象
C:提供公共访问方式
(3)代码实现:
A:饿汉式
public class Student {
private Student(){}
private static Student s = new Student();
public static Student getStudent() {
return s;
}
}
B:懒汉式
public class Student {
private Student(){}
private static Student s = null;
public static Student getStudent() {
if(s == null) {
s = new Student();
}
return s;
}
}
(4)面试和开发
A:面试
懒汉式
线程安全问题 必须要synchronized关键字
延迟加载思想
B:开发
饿汉式
(5)Runtime
是单例模式饿汉式实现。
public class Runtime{
private Runtime(){}
private static Runtime r = new Runtime();
public static Runtime getInstance(){
return r;
}
}
You can’t perform that action at this time.