did slight changes in terms of synchronization to hopefully prevent the atypical crashes of undefined behaviour due to string list being used while being added to

This commit is contained in:
christian 2021-12-01 18:59:02 +01:00
parent b39d27129e
commit 59c255e615
3 changed files with 12 additions and 11 deletions

View File

@ -158,6 +158,7 @@ public class Datahandler {
return StanfordCoreNLP(propsSentiment) return StanfordCoreNLP(propsSentiment)
} }
@Synchronized
fun updateStringCache() { fun updateStringCache() {
if (stopwatch.elapsed(TimeUnit.MINUTES) >= EXPIRE_TIME_IN_MINUTES || !stopwatch.isRunning) { if (stopwatch.elapsed(TimeUnit.MINUTES) >= EXPIRE_TIME_IN_MINUTES || !stopwatch.isRunning) {
if (!stopwatch.isRunning) { if (!stopwatch.isRunning) {
@ -170,15 +171,16 @@ public class Datahandler {
val arrayList = java.util.ArrayList<String>(stringCache) val arrayList = java.util.ArrayList<String>(stringCache)
DataMapper.InsertMYSQLStrings(arrayList) DataMapper.InsertMYSQLStrings(arrayList)
DataMapper.checkStringsToDelete(); DataMapper.checkStringsToDelete();
stringCache = ArrayList<String>(); for (str: String in DataMapper.getAllStrings()) {
initiateMYSQL(); if (str in stringCache) {
continue
}
stringCache.add(str)
}
System.out.println("post updateStringCache");
} }
} }
fun initiateMYSQL() {
stringCache.addAll(DataMapper.getAllStrings())
}
private fun trimString(str: String): String { private fun trimString(str: String): String {
var message = str.trim { it <= ' ' } var message = str.trim { it <= ' ' }
if (message.startsWith("<@")) { if (message.startsWith("<@")) {

View File

@ -26,15 +26,15 @@ import reactor.core.publisher.Mono;
*/ */
public class DoStuff { public class DoStuff {
public synchronized static void doStuff(MessageCreateEvent event, String usernameBot, Datahandler datahandler,
public static void doStuff(MessageCreateEvent event, String usernameBot, Datahandler datahandler, StanfordCoreNLP stanfordCoreNLP, StanfordCoreNLP stanfordCoreNLPSentiment) {
StanfordCoreNLP stanfordCoreNLP, StanfordCoreNLP stanfordCoreNLPSentiment) {
String username = ""; String username = "";
try { try {
username = event.getMessage().getAuthor().get().getUsername(); username = event.getMessage().getAuthor().get().getUsername();
} catch (java.util.NoSuchElementException e) { } catch (java.util.NoSuchElementException e) {
username = null; username = null;
} }
datahandler.updateStringCache();
if (username != null && !username.equals(usernameBot)) { if (username != null && !username.equals(usernameBot)) {
TextChannel block = event.getMessage().getChannel().cast(TextChannel.class).block(); TextChannel block = event.getMessage().getChannel().cast(TextChannel.class).block();
String name = block.getCategory().block().getName(); String name = block.getCategory().block().getName();
@ -81,7 +81,6 @@ public class DoStuff {
} }
} }
} }
datahandler.updateStringCache();
} }
} }
} }

View File

@ -80,7 +80,7 @@ public class DiscordHandler {
//variables until the tests pass //variables until the tests pass
public static void main(String[] args) throws IOException, SQLException { public static void main(String[] args) throws IOException, SQLException {
Datahandler datahandler = new Datahandler(); Datahandler datahandler = new Datahandler();
datahandler.initiateMYSQL(); datahandler.updateStringCache();
PipelineJMWESingleton.getINSTANCE(); PipelineJMWESingleton.getINSTANCE();
StanfordCoreNLP stanfordCoreNLP = datahandler.pipeLineSetUp(); StanfordCoreNLP stanfordCoreNLP = datahandler.pipeLineSetUp();