mirror of
https://github.com/Estom/notes.git
synced 2026-02-04 19:13:24 +08:00
Java内容重新整理删除过期的东西
This commit is contained in:
25
Java/JavaDemo/jdk21demo/VirtualThreadTest.java
Normal file
25
Java/JavaDemo/jdk21demo/VirtualThreadTest.java
Normal file
@@ -0,0 +1,25 @@
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class VirtualThreadTest {
|
||||
public static void main(String[] args) {
|
||||
// long start = System.currentTimeMillis();
|
||||
// try (ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor()) {
|
||||
try (ExecutorService executor = Executors.newFixedThreadPool(10)) {
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
final int index = i;
|
||||
executor.submit(() -> {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Thread.sleep(1000);
|
||||
System.out.println(Thread.currentThread().getName() + ": " + index + " is running");
|
||||
});
|
||||
}
|
||||
}
|
||||
// long end = System.currentTimeMillis();
|
||||
// System.out.println("Total time: " + (end - start) + " ms");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user