added threadpool to handle secondary processes. Should max be two threads and the main thread in use now

This commit is contained in:
christian 2021-12-06 18:38:15 +01:00
parent 6006f50bcb
commit e9969f836e

View File

@ -20,6 +20,8 @@ import java.net.*;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
@ -87,6 +89,7 @@ public class DiscordHandler extends ListenerAdapter {
private static StanfordCoreNLP stanfordCoreNLP;
private static Datahandler datahandler;
private static StanfordCoreNLP stanfordCoreNLPSentiment;
private static ExecutorService executorService = Executors.newFixedThreadPool(2);
//TODO add python program that edits the java code. python program just adds test if statements on
//variables until the tests pass
@ -168,11 +171,13 @@ public class DiscordHandler extends ListenerAdapter {
}
} else {
final String contentF = content;
//these should be able to run on their own.
new Thread(() -> {
String strF = datahandler.trimString(contentF);
datahandler.getResponseFutures(strF, stanfordCoreNLP, stanfordCoreNLPSentiment);
}).start();
executorService.execute(new Runnable() {
@Override
public void run() {
String strF = datahandler.trimString(contentF);
datahandler.getResponseFutures(strF, stanfordCoreNLP, stanfordCoreNLPSentiment);
}
});
}
}
}