forked from DreamCats/java-notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathT18.java
More file actions
35 lines (28 loc) · 708 Bytes
/
T18.java
File metadata and controls
35 lines (28 loc) · 708 Bytes
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
package com.basic;
import java.util.Arrays;
/**
* @program JavaBooks
* @description: 单例,内部类方式,不需要加锁
* @author: mf
* @create: 2019/12/31 11:17
*/
public class T18 {
private T18() {
System.out.println("single");
}
private static class Inner {
private static T18 s = new T18();
}
private static T18 getSingle() {
return Inner.s;
}
public static void main(String[] args) {
Thread[] ths = new Thread[100];
for (int i = 0; i < ths.length; i++) {
ths[i] = new Thread(() -> {
T18.getSingle();
});
}
Arrays.asList(ths).forEach(o -> o.start());
}
}