get methods should be quicker than loops, new thread avoids waiting for datamapper insert

This commit is contained in:
jenzur 2019-03-26 22:57:13 +01:00
parent 511eb0e492
commit 296be21753

View File

@ -266,6 +266,7 @@ public class Datahandler {
} }
} }
//synchronized
public synchronized void updateMatrixes() { public synchronized void updateMatrixes() {
refreshMatrixFromDB = false; refreshMatrixFromDB = false;
if (stopwatch1.elapsed(TimeUnit.SECONDS) >= EXPIRE_TIME_IN_SECONDS1) { if (stopwatch1.elapsed(TimeUnit.SECONDS) >= EXPIRE_TIME_IN_SECONDS1) {
@ -280,14 +281,8 @@ public class Datahandler {
LinkedHashMap<String, LinkedHashMap<String, Double>> LHMSMXLocal = lHMSMX; LinkedHashMap<String, LinkedHashMap<String, Double>> LHMSMXLocal = lHMSMX;
int ij2 = 0; int ij2 = 0;
for (String str : stringCachelocal.values()) { for (String str : stringCachelocal.values()) {
boolean updatepresent = false; LinkedHashMap<String, Double> orDefault = LHMSMXLocal.getOrDefault(str, null);
for (String strlocal : LHMSMXLocal.keySet()) { if (orDefault == null) {
if (strlocal.equals(str)) {
updatepresent = true;
break;
}
}
if (!updatepresent) {
selectUpdate = ij2; selectUpdate = ij2;
break; break;
} }
@ -308,25 +303,17 @@ public class Datahandler {
boolean present = false; boolean present = false;
LinkedHashMap<String, Double> orDefault = lHMSMX.getOrDefault(getStringCacheStr, null); LinkedHashMap<String, Double> orDefault = lHMSMX.getOrDefault(getStringCacheStr, null);
if (orDefault != null) { if (orDefault != null) {
Iterator<String> strDefaultsItr = orDefault.keySet().iterator(); Double orDefault1 = orDefault.getOrDefault(str1, null);
while (strDefaultsItr.hasNext()) { if (orDefault1 != null) {
String strkey = strDefaultsItr.next();
if (strkey.equals(str1)) {
present = true; present = true;
break;
}
} }
} }
if (!present) { if (!present) {
orDefault = lHMSMX.getOrDefault(str1, null); orDefault = lHMSMX.getOrDefault(str1, null);
if (orDefault != null) { if (orDefault != null) {
Iterator<String> strDefaultsItr = orDefault.keySet().iterator(); Double orDefault1 = orDefault.getOrDefault(getStringCacheStr, null);
while (strDefaultsItr.hasNext()) { if (orDefault1 != null) {
String strkey = strDefaultsItr.next();
if (strkey.equals(getStringCacheStr)) {
present = true; present = true;
break;
}
} }
} }
} }
@ -360,6 +347,7 @@ public class Datahandler {
matrixUpdateList.put(matrixUpdateList.size() + 1, SMX); matrixUpdateList.put(matrixUpdateList.size() + 1, SMX);
} }
}); });
new Thread(() -> {
try { try {
if (!matrixUpdateList.isEmpty()) { if (!matrixUpdateList.isEmpty()) {
DataMapper.insertSementicMatrixes(matrixUpdateList); DataMapper.insertSementicMatrixes(matrixUpdateList);
@ -369,7 +357,9 @@ public class Datahandler {
Logger.getLogger(Datahandler.class Logger.getLogger(Datahandler.class
.getName()).log(Level.SEVERE, null, ex); .getName()).log(Level.SEVERE, null, ex);
} }
}).start();
} }
} }
public synchronized void checkIfUpdateStrings(boolean hlStatsMsg) throws CustomError { public synchronized void checkIfUpdateStrings(boolean hlStatsMsg) throws CustomError {