Create the webserver-connection syncronized

to make sure it is fully started before it can get closed again. Fixes #89
This commit is contained in:
Blue (Lukas Rieger) 2020-09-16 10:26:57 +02:00
parent 3b6ed4c297
commit b8cd92b507

View File

@ -59,7 +59,7 @@ public WebServer(int port, int maxConnections, InetAddress bindAdress, HttpReque
} }
@Override @Override
public void run(){ public synchronized void start() {
close(); close();
connectionThreads = new ThreadPoolExecutor(maxConnections, maxConnections, 10, TimeUnit.SECONDS, new LinkedBlockingQueue<>()); connectionThreads = new ThreadPoolExecutor(maxConnections, maxConnections, 10, TimeUnit.SECONDS, new LinkedBlockingQueue<>());
@ -73,6 +73,13 @@ public void run(){
return; return;
} }
super.start();
}
@Override
public void run(){
if (server == null) return;
Logger.global.logInfo("WebServer started."); Logger.global.logInfo("WebServer started.");
while (!server.isClosed() && server.isBound()){ while (!server.isClosed() && server.isBound()){
@ -98,7 +105,7 @@ public void run(){
Logger.global.logInfo("WebServer closed."); Logger.global.logInfo("WebServer closed.");
} }
public void close(){ public synchronized void close(){
if (connectionThreads != null) connectionThreads.shutdown(); if (connectionThreads != null) connectionThreads.shutdown();
try { try {