forked from wesleyegberto/java-new-features
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebServerThreads.java
More file actions
22 lines (19 loc) · 719 Bytes
/
WebServerThreads.java
File metadata and controls
22 lines (19 loc) · 719 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import com.sun.net.httpserver.*;
import java.net.*;
import java.io.*;
import java.nio.file.*;
import java.util.function.Predicate;
import java.util.concurrent.Executors;
/**
* Run: `java --enable-preview --source 19 WebServerThreads.java`
*/
public class WebServerThreads {
public static void main(String[] args) throws IOException {
var server = HttpServer.create(new InetSocketAddress(8000), 0);
server.createContext("/", HttpHandlers.of(200, new Headers(), "Handled!"));
// server.setExecutor(Executors.newCachedThreadPool());
server.setExecutor(Executors.newThreadPerTaskExecutor(Thread.ofVirtual().factory()));
server.start();
System.out.println("Server started at " + server.getAddress());
}
}