forked from wesleyegberto/java-new-features
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVirtualThreadHelloWorld.java
More file actions
28 lines (25 loc) · 861 Bytes
/
Copy pathVirtualThreadHelloWorld.java
File metadata and controls
28 lines (25 loc) · 861 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
/**
* Simple project to show how to use the VirtualThread.
* To run: `java --enable-preview --source 19 VirtualThreadHelloWorld.java`
*/
public class VirtualThreadHelloWorld {
public static void main(String[] args) throws Exception {
Thread.startVirtualThread(() -> {
String name = Thread.currentThread().getName();
System.out.printf("Hello World from virtual Thread called %s!\n", name);
});
Thread.ofVirtual()
.name("Virtual-Thread-From-Builder")
.start(() -> {
String name = Thread.currentThread().getName();
System.out.printf("Hello World from virtual Thread called %s!\n", name);
});
Thread.ofPlatform()
.name("Real-Thread-From-Builder")
.start(() -> {
String name = Thread.currentThread().getName();
System.out.printf("Hello World from real Thread called %s!\n", name);
});
Thread.sleep(5000);
}
}