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 9324910798
commit a8f5d2f20f
3 changed files with 12 additions and 11 deletions

View File

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

View File

@ -26,15 +26,15 @@ import reactor.core.publisher.Mono;
*/
public class DoStuff {
public static void doStuff(MessageCreateEvent event, String usernameBot, Datahandler datahandler,
StanfordCoreNLP stanfordCoreNLP, StanfordCoreNLP stanfordCoreNLPSentiment) {
public synchronized static void doStuff(MessageCreateEvent event, String usernameBot, Datahandler datahandler,
StanfordCoreNLP stanfordCoreNLP, StanfordCoreNLP stanfordCoreNLPSentiment) {
String username = "";
try {
username = event.getMessage().getAuthor().get().getUsername();
} catch (java.util.NoSuchElementException e) {
username = null;
}
datahandler.updateStringCache();
if (username != null && !username.equals(usernameBot)) {
TextChannel block = event.getMessage().getChannel().cast(TextChannel.class).block();
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
public static void main(String[] args) throws IOException, SQLException {
Datahandler datahandler = new Datahandler();
datahandler.initiateMYSQL();
datahandler.updateStringCache();
PipelineJMWESingleton.getINSTANCE();
StanfordCoreNLP stanfordCoreNLP = datahandler.pipeLineSetUp();