#12 -- Fix threads

This commit is contained in:
Anton Romanov 2024-11-25 11:24:58 +04:00
parent dbcadcb4aa
commit 4e6c79f837

View File

@ -33,7 +33,8 @@ class MethodParamBruteForce {
private final int DEFAULT_THREAD_COUNT = 50; private final int DEFAULT_THREAD_COUNT = 50;
private final List<Method> methods; private final List<Method> methods;
private final ScoreMethod scoreMethod = new Smape(); private final ScoreMethod scoreMethod = new Smape();
private final ExecutorService executors = Executors.newFixedThreadPool(DEFAULT_THREAD_COUNT); private final ExecutorService executors = Executors.newCachedThreadPool();
;
public MethodParamBruteForce(List<Method> methods) { public MethodParamBruteForce(List<Method> methods) {
this.methods = methods; this.methods = methods;
@ -74,7 +75,7 @@ class MethodParamBruteForce {
for (Future<ModelingResult> futureModelingResult : futureModelingResults) { for (Future<ModelingResult> futureModelingResult : futureModelingResults) {
modelingResults.add(futureModelingResult.get()); modelingResults.add(futureModelingResult.get());
} }
System.gc();
return getBestResultForecast(modelingResults, timeSeries, countPoints); return getBestResultForecast(modelingResults, timeSeries, countPoints);
} }
@ -159,6 +160,7 @@ class MethodParamBruteForce {
for (Future<ModelingResult> futureModelingResult : results) { for (Future<ModelingResult> futureModelingResult : results) {
results2.add(futureModelingResult.get()); results2.add(futureModelingResult.get());
} }
System.gc();
return results2.stream() return results2.stream()
.min(Comparator.comparing(modelingResult -> modelingResult.getScore().getDoubleValue())) .min(Comparator.comparing(modelingResult -> modelingResult.getScore().getDoubleValue()))
.orElse(null); .orElse(null);
@ -189,6 +191,7 @@ class MethodParamBruteForce {
for (Future<ModelingResult> futureModelingResult : results) { for (Future<ModelingResult> futureModelingResult : results) {
results2.add(futureModelingResult.get()); results2.add(futureModelingResult.get());
} }
System.gc();
return results2.stream() return results2.stream()
.min(Comparator.comparing(modelingResult -> modelingResult.getScore().getDoubleValue())) .min(Comparator.comparing(modelingResult -> modelingResult.getScore().getDoubleValue()))
.orElse(null); .orElse(null);