Skip to content

Commit 9eade36

Browse files
committed
feat: update
1 parent c5a1f6a commit 9eade36

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

java-17/src/main/java/com/di1shuai/java17/instanceofcase/InstanceOfCase.java

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ public class InstanceOfCase {
88

99
public static void main(String[] args) {
1010
JDK17_instanceof_switch(1);
11+
JDK17_before_instanceof_switch(1);
12+
JDK13_switch();
13+
JDK12_switch();
14+
JDK11_switch();
1115
}
1216

1317
public static void JDK17_instanceof_switch(Object o) {

java-19/src/main/java/com/di1shuai/java19/recordcase/Point.java

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public static void main(String[] args) {
77
Point point = new Point(1, 2);
88
System.out.println(point);
99
System.out.println(point.x());
10+
System.out.println(point.y());
1011

1112
}
1213

java-19/src/main/java/com/di1shuai/java19/virthread/Jep425Demo.java

+26-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@
77
import java.util.stream.IntStream;
88

99
public class Jep425Demo {
10+
11+
12+
public static void main(String[] args) {
13+
long startTime = System.currentTimeMillis();
14+
firstVirtualThread();
15+
System.out.printf("VirtualThread finished, time cost %d ms\n",
16+
System.currentTimeMillis() - startTime);
17+
18+
firstThread();
19+
System.out.printf("Thread finished, time cost %d ms\n",
20+
System.currentTimeMillis() - startTime);
21+
22+
}
23+
24+
25+
1026
public static void firstVirtualThread() {
1127
// 创建10000个虚拟线程
1228
try (var executor = Executors.newVirtualThreadPerTaskExecutor()) {
@@ -19,14 +35,18 @@ public static void firstVirtualThread() {
1935
} // try-with-resources,会隐式调用executor.close()
2036
}
2137

22-
public static void main(String[] args) {
23-
long startTime = System.currentTimeMillis();
24-
firstVirtualThread();
25-
System.out.printf("firstVirtualThread finished, time cost %d ms\n",
26-
System.currentTimeMillis() - startTime);
38+
public static void firstThread() {
39+
// 创建10000个线程
40+
try (var executor = Executors.newFixedThreadPool(1000)) {
41+
IntStream.range(0, 10_000).forEach(i -> {
42+
executor.submit(() -> {
43+
Thread.sleep(Duration.ofSeconds(1));
44+
return i;
45+
});
46+
});
47+
} // try-with-resources,会隐式调用executor.close()
2748
}
2849

29-
3050
private static void infoCurrentThread() {
3151
Thread thread = Thread.currentThread();
3252
System.out.printf("线程名称: %s,是否虚拟线程: %s\n",

0 commit comments

Comments
 (0)