-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPI.java
More file actions
29 lines (21 loc) · 839 Bytes
/
API.java
File metadata and controls
29 lines (21 loc) · 839 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
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import com.sun.net.httpserver.*;
class API
{
public static void main(String[] args) {
try {
HttpServer server = HttpServer.create(new InetSocketAddress("localhost", 8080), 0);
server.createContext("/api", new DummyAPI());
int cpuCount = Runtime.getRuntime().availableProcessors();
ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor)Executors.newFixedThreadPool(cpuCount);
server.setExecutor(threadPoolExecutor);
server.start();
System.out.println("API server started.");
} catch (IOException e) {
e.printStackTrace();
}
}
}