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