Skip to content

Commit

Permalink
Fixed memory leaks in Thread Pool.
Browse files Browse the repository at this point in the history
  • Loading branch information
irinil committed Jul 29, 2020
1 parent 4c7a529 commit 1e032f1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Expand Up @@ -5,6 +5,7 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;

import de.tudarmstadt.informatik.hostage.protocol.COAP;
import de.tudarmstadt.informatik.hostage.protocol.Protocol;
Expand Down Expand Up @@ -111,13 +112,14 @@ public void stopServer(){
}
}

private void fullHandler() {
private void fullHandler() throws InterruptedException {
if (conReg.isConnectionFree()) {
ExecutorService threadPool = Executors.newFixedThreadPool(1);
ExecutorService threadPool = Executors.newCachedThreadPool();

Thread serverThread = serverThread();
threadPool.submit(serverThread);
threadPool.shutdown();
threadPool.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
}
}

Expand Down
@@ -1,6 +1,8 @@
package de.tudarmstadt.informatik.hostage;

import java.io.IOException;
import java.net.URISyntaxException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Timer;
Expand Down Expand Up @@ -121,12 +123,13 @@ public void stopMqttBroker(){

private void fullHandler() throws Exception {
if (conReg.isConnectionFree()) {
ExecutorService threadPool = Executors.newFixedThreadPool(1);
ExecutorService threadPool = Executors.newCachedThreadPool();

Thread brokerThread = brokerThread();
threadPool.submit(brokerThread);
startsMonitoringProfile();
threadPool.shutdown();
threadPool.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
}
}

Expand Down

0 comments on commit 1e032f1

Please sign in to comment.