removed threads from inside of matrixupdate, made executor be instance based and not shut down
This commit is contained in:
parent
7f154f3456
commit
1fe4a268c4
@ -25,7 +25,6 @@ import edu.stanford.nlp.trees.Tree;
|
|||||||
import edu.stanford.nlp.trees.TreebankLanguagePack;
|
import edu.stanford.nlp.trees.TreebankLanguagePack;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.lang.management.ManagementFactory;
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -40,7 +39,6 @@ import java.util.concurrent.Callable;
|
|||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.ForkJoinPool;
|
import java.util.concurrent.ForkJoinPool;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@ -59,7 +57,6 @@ public class MYSQLDatahandler {
|
|||||||
public static int semeticsUpdateCount;
|
public static int semeticsUpdateCount;
|
||||||
private static int counter = 0;
|
private static int counter = 0;
|
||||||
private volatile boolean refreshMatrixFromDB;
|
private volatile boolean refreshMatrixFromDB;
|
||||||
private volatile boolean permitted = false;
|
|
||||||
private final ConcurrentMap<Integer, String> stringCache;
|
private final ConcurrentMap<Integer, String> stringCache;
|
||||||
private LinkedHashMap<String, LinkedHashMap<String, Double>> lHMSMX = new LinkedHashMap();
|
private LinkedHashMap<String, LinkedHashMap<String, Double>> lHMSMX = new LinkedHashMap();
|
||||||
private ConcurrentMap<Integer, String> multiprocessCalculations;
|
private ConcurrentMap<Integer, String> multiprocessCalculations;
|
||||||
@ -80,6 +77,7 @@ public class MYSQLDatahandler {
|
|||||||
private static LexicalizedParser lp;
|
private static LexicalizedParser lp;
|
||||||
private static TreebankLanguagePack tlp;
|
private static TreebankLanguagePack tlp;
|
||||||
private static AbstractSequenceClassifier<CoreLabel> classifier;
|
private static AbstractSequenceClassifier<CoreLabel> classifier;
|
||||||
|
private ExecutorService executor;
|
||||||
private static StanfordCoreNLP pipeline;
|
private static StanfordCoreNLP pipeline;
|
||||||
private static StanfordCoreNLP pipelineSentiment;
|
private static StanfordCoreNLP pipelineSentiment;
|
||||||
|
|
||||||
@ -91,6 +89,12 @@ public class MYSQLDatahandler {
|
|||||||
MYSQLDatahandler.classifier = classifier;
|
MYSQLDatahandler.classifier = classifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void instantiateExecutor() {
|
||||||
|
this.executor = new ForkJoinPool(Runtime.getRuntime().availableProcessors(),
|
||||||
|
ForkJoinPool.defaultForkJoinWorkerThreadFactory,
|
||||||
|
null, true);
|
||||||
|
}
|
||||||
|
|
||||||
public MYSQLDatahandler() {
|
public MYSQLDatahandler() {
|
||||||
this.stopwatch = Stopwatch.createUnstarted();
|
this.stopwatch = Stopwatch.createUnstarted();
|
||||||
this.stopwatch1 = Stopwatch.createStarted();
|
this.stopwatch1 = Stopwatch.createStarted();
|
||||||
@ -161,6 +165,14 @@ public class MYSQLDatahandler {
|
|||||||
return LHM;
|
return LHM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getlHMSMXSize() {
|
||||||
|
return lHMSMX.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getstringCacheSize() {
|
||||||
|
return stringCache.size();
|
||||||
|
}
|
||||||
|
|
||||||
public void initiateMYSQL() throws SQLException, IOException {
|
public void initiateMYSQL() throws SQLException, IOException {
|
||||||
try {
|
try {
|
||||||
DataMapper.createTables();
|
DataMapper.createTables();
|
||||||
@ -174,9 +186,8 @@ public class MYSQLDatahandler {
|
|||||||
|
|
||||||
public synchronized void checkIfUpdateMatrixes() {
|
public synchronized void checkIfUpdateMatrixes() {
|
||||||
refreshMatrixFromDB = false;
|
refreshMatrixFromDB = false;
|
||||||
int calculationBoundaries = 10;
|
int calculationBoundaries = 5;
|
||||||
int updateBadgesInteger = 250;
|
int updateBadgesInteger = 250;
|
||||||
while (lHMSMX.size() < (stringCache.values().size() * stringCache.values().size()) - stringCache.values().size()) {
|
|
||||||
if (stopwatch1.elapsed(TimeUnit.SECONDS) >= EXPIRE_TIME_IN_SECONDS1) {
|
if (stopwatch1.elapsed(TimeUnit.SECONDS) >= EXPIRE_TIME_IN_SECONDS1) {
|
||||||
refreshMatrixFromDB = true;
|
refreshMatrixFromDB = true;
|
||||||
lHMSMX = DataMapper.getAllRelationScores();
|
lHMSMX = DataMapper.getAllRelationScores();
|
||||||
@ -235,11 +246,6 @@ public class MYSQLDatahandler {
|
|||||||
}
|
}
|
||||||
ConcurrentMap<Integer, SimilarityMatrix> matrixUpdateList = new MapMaker().concurrencyLevel(2).makeMap();
|
ConcurrentMap<Integer, SimilarityMatrix> matrixUpdateList = new MapMaker().concurrencyLevel(2).makeMap();
|
||||||
ConcurrentMap<Integer, Future<SimilarityMatrix>> futures = new MapMaker().concurrencyLevel(2).makeMap();
|
ConcurrentMap<Integer, Future<SimilarityMatrix>> futures = new MapMaker().concurrencyLevel(2).makeMap();
|
||||||
System.out.println("activecount: " + java.lang.Thread.activeCount() + "\nThreadCount: " + ManagementFactory.getThreadMXBean().getThreadCount()
|
|
||||||
+ "\navailableprocessors: " + Runtime.getRuntime().availableProcessors() + "\n");
|
|
||||||
ExecutorService executor = new ForkJoinPool(Runtime.getRuntime().availableProcessors(),
|
|
||||||
ForkJoinPool.defaultForkJoinWorkerThreadFactory,
|
|
||||||
null, true);
|
|
||||||
strIndexNavigatorL.values().forEach((str) -> {
|
strIndexNavigatorL.values().forEach((str) -> {
|
||||||
randomIndexesToUpdate.values().stream().filter((str1) -> (!str.equals(str1))).forEachOrdered((str1) -> {
|
randomIndexesToUpdate.values().stream().filter((str1) -> (!str.equals(str1))).forEachOrdered((str1) -> {
|
||||||
boolean present = false;
|
boolean present = false;
|
||||||
@ -263,7 +269,6 @@ public class MYSQLDatahandler {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
executor.shutdown();
|
|
||||||
try {
|
try {
|
||||||
System.out.println("finished worker assignment, futures size: " + futures.size() + "\n");
|
System.out.println("finished worker assignment, futures size: " + futures.size() + "\n");
|
||||||
for (Future<SimilarityMatrix> future : futures.values()) {
|
for (Future<SimilarityMatrix> future : futures.values()) {
|
||||||
@ -290,15 +295,10 @@ public class MYSQLDatahandler {
|
|||||||
.getName()).log(Level.SEVERE, null, ex);
|
.getName()).log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
} else if (!permitted) {
|
} else {
|
||||||
permitted = true;
|
|
||||||
new Thread(() -> {
|
|
||||||
ConcurrentMap<Integer, String> stringCachelocal = stringCache;
|
ConcurrentMap<Integer, String> stringCachelocal = stringCache;
|
||||||
ConcurrentMap<Integer, SimilarityMatrix> matrixUpdateList = new MapMaker().concurrencyLevel(2).makeMap();
|
ConcurrentMap<Integer, SimilarityMatrix> matrixUpdateList = new MapMaker().concurrencyLevel(2).makeMap();
|
||||||
ConcurrentMap<Integer, Future<SimilarityMatrix>> futures = new MapMaker().concurrencyLevel(2).makeMap();
|
ConcurrentMap<Integer, Future<SimilarityMatrix>> futures = new MapMaker().concurrencyLevel(2).makeMap();
|
||||||
ExecutorService executor = new ForkJoinPool(Runtime.getRuntime().availableProcessors(),
|
|
||||||
ForkJoinPool.defaultForkJoinWorkerThreadFactory,
|
|
||||||
null, true);
|
|
||||||
Collection<String> values = multiprocessCalculations.values();
|
Collection<String> values = multiprocessCalculations.values();
|
||||||
LinkedHashMap<String, LinkedHashMap<String, Double>> LHMSMXLocal = lHMSMX;
|
LinkedHashMap<String, LinkedHashMap<String, Double>> LHMSMXLocal = lHMSMX;
|
||||||
values.forEach((str) -> {
|
values.forEach((str) -> {
|
||||||
@ -322,7 +322,6 @@ public class MYSQLDatahandler {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
executor.shutdown();
|
|
||||||
try {
|
try {
|
||||||
System.out.println("finished worker assignment, futures size: " + futures.size() + "\n");
|
System.out.println("finished worker assignment, futures size: " + futures.size() + "\n");
|
||||||
for (Future<SimilarityMatrix> future : futures.values()) {
|
for (Future<SimilarityMatrix> future : futures.values()) {
|
||||||
@ -338,12 +337,11 @@ public class MYSQLDatahandler {
|
|||||||
} catch (InterruptedException | ExecutionException ex) {
|
} catch (InterruptedException | ExecutionException ex) {
|
||||||
Logger.getLogger(MYSQLDatahandler.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(MYSQLDatahandler.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
new Thread(() -> {
|
|
||||||
try {
|
|
||||||
multiprocessCalculations = new MapMaker().concurrencyLevel(2).makeMap();
|
multiprocessCalculations = new MapMaker().concurrencyLevel(2).makeMap();
|
||||||
updatedRows = new ArrayList();
|
updatedRows = new ArrayList();
|
||||||
counter = 0;
|
counter = 0;
|
||||||
permitted = false;
|
new Thread(() -> {
|
||||||
|
try {
|
||||||
if (!matrixUpdateList.isEmpty()) {
|
if (!matrixUpdateList.isEmpty()) {
|
||||||
DataMapper.insertSementicMatrixes(matrixUpdateList);
|
DataMapper.insertSementicMatrixes(matrixUpdateList);
|
||||||
System.out.println("finished datamapper semetic insert");
|
System.out.println("finished datamapper semetic insert");
|
||||||
@ -353,8 +351,6 @@ public class MYSQLDatahandler {
|
|||||||
.getName()).log(Level.SEVERE, null, ex);
|
.getName()).log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}).start();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -434,16 +430,12 @@ public class MYSQLDatahandler {
|
|||||||
System.out.println("none within 8 range");
|
System.out.println("none within 8 range");
|
||||||
ConcurrentMap<Integer, String> strCache = stringCache;
|
ConcurrentMap<Integer, String> strCache = stringCache;
|
||||||
ConcurrentMap<Integer, Future<SimilarityMatrix>> futureslocal = new MapMaker().concurrencyLevel(2).makeMap();
|
ConcurrentMap<Integer, Future<SimilarityMatrix>> futureslocal = new MapMaker().concurrencyLevel(2).makeMap();
|
||||||
ExecutorService executor = new ForkJoinPool(Runtime.getRuntime().availableProcessors(),
|
|
||||||
ForkJoinPool.defaultForkJoinWorkerThreadFactory,
|
|
||||||
null, true);
|
|
||||||
for (String str1 : strCache.values()) {
|
for (String str1 : strCache.values()) {
|
||||||
if (!str.equals(str1)) {
|
if (!str.equals(str1)) {
|
||||||
Callable<SimilarityMatrix> worker = new SentimentAnalyzerTest(str, str1, new SimilarityMatrix(str, str1));
|
Callable<SimilarityMatrix> worker = new SentimentAnalyzerTest(str, str1, new SimilarityMatrix(str, str1));
|
||||||
futureslocal.put(futureslocal.size() + 1, executor.submit(worker));
|
futureslocal.put(futureslocal.size() + 1, executor.submit(worker));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
executor.shutdown();
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (Future<SimilarityMatrix> future : futureslocal.values()) {
|
for (Future<SimilarityMatrix> future : futureslocal.values()) {
|
||||||
try {
|
try {
|
||||||
@ -469,13 +461,9 @@ public class MYSQLDatahandler {
|
|||||||
int minDistance = 8;
|
int minDistance = 8;
|
||||||
String similar = "";
|
String similar = "";
|
||||||
ConcurrentMap<Integer, Future<DistanceObject>> futures = new MapMaker().concurrencyLevel(2).makeMap();
|
ConcurrentMap<Integer, Future<DistanceObject>> futures = new MapMaker().concurrencyLevel(2).makeMap();
|
||||||
ExecutorService executor = new ForkJoinPool(Runtime.getRuntime().availableProcessors(),
|
|
||||||
ForkJoinPool.defaultForkJoinWorkerThreadFactory,
|
|
||||||
null, true);
|
|
||||||
concurrentStrings.values().stream().map((str) -> new LevenshteinDistance(str, toBeCompared, new DistanceObject())).forEachOrdered((worker) -> {
|
concurrentStrings.values().stream().map((str) -> new LevenshteinDistance(str, toBeCompared, new DistanceObject())).forEachOrdered((worker) -> {
|
||||||
futures.put(futures.size() + 1, executor.submit(worker));
|
futures.put(futures.size() + 1, executor.submit(worker));
|
||||||
});
|
});
|
||||||
executor.shutdown();
|
|
||||||
try {
|
try {
|
||||||
for (Future<DistanceObject> future : futures.values()) {
|
for (Future<DistanceObject> future : futures.values()) {
|
||||||
DistanceObject d = future.get();
|
DistanceObject d = future.get();
|
||||||
|
@ -44,7 +44,11 @@ public class DiscordHandler {
|
|||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
MYSQLDatahandler.shiftReduceParserInitiate();
|
MYSQLDatahandler.shiftReduceParserInitiate();
|
||||||
|
MYSQLDatahandler.instance.instantiateExecutor();
|
||||||
|
while (MYSQLDatahandler.instance.getlHMSMXSize() < (MYSQLDatahandler.instance.getstringCacheSize()
|
||||||
|
* MYSQLDatahandler.instance.getstringCacheSize()) - MYSQLDatahandler.instance.getstringCacheSize()) {
|
||||||
MYSQLDatahandler.instance.checkIfUpdateMatrixes();
|
MYSQLDatahandler.instance.checkIfUpdateMatrixes();
|
||||||
|
}
|
||||||
String token = "NTI5NzAxNTk5NjAyMjc4NDAx.Dw0vDg.7-aMjVWdQMYPl8qVNyvTCPS5F_A";
|
String token = "NTI5NzAxNTk5NjAyMjc4NDAx.Dw0vDg.7-aMjVWdQMYPl8qVNyvTCPS5F_A";
|
||||||
DiscordApi api = new DiscordApiBuilder().setToken(token).login().join();
|
DiscordApi api = new DiscordApiBuilder().setToken(token).login().join();
|
||||||
api.addMessageCreateListener(event -> {
|
api.addMessageCreateListener(event -> {
|
||||||
|
Loading…
Reference in New Issue
Block a user