Attempt at server multi-threading
Does this look good to you @NorbiPeti? I have no clue how to thread, but I followed a tutorial. Does this seem like a safe thread? Locks and all that stuff.
This commit is contained in:
parent
ad2958b59c
commit
e19291139c
1 changed files with 36 additions and 18 deletions
|
@ -17,6 +17,22 @@ public abstract class Page implements HttpHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(HttpExchange exchange) {
|
public void handle(HttpExchange exchange) {
|
||||||
|
|
||||||
|
//Creates a new thread to handle the request
|
||||||
|
Handler handler = new Handler(exchange);
|
||||||
|
handler.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
class Handler extends Thread{
|
||||||
|
|
||||||
|
HttpExchange exchange;
|
||||||
|
|
||||||
|
public Handler(HttpExchange exchange){
|
||||||
|
this.exchange = exchange;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(){
|
||||||
try {
|
try {
|
||||||
exchange.getResponseHeaders().add("Access-Control-Allow-Origin", "https://tbmcplugins.github.io");
|
exchange.getResponseHeaders().add("Access-Control-Allow-Origin", "https://tbmcplugins.github.io");
|
||||||
if (exchange.getRequestURI().getPath().equals("/" + GetName()))
|
if (exchange.getRequestURI().getPath().equals("/" + GetName()))
|
||||||
|
@ -38,6 +54,8 @@ public abstract class Page implements HttpHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main logic of the endpoint. Use IOHelper to retrieve the message sent and other things.
|
* The main logic of the endpoint. Use IOHelper to retrieve the message sent and other things.
|
||||||
|
|
Loading…
Reference in a new issue