From 4e6c79f83728917c28348bebf9a6848db66b4a62 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 25 Nov 2024 11:24:58 +0400 Subject: [PATCH] #12 -- Fix threads --- src/main/java/ru/ulstu/service/MethodParamBruteForce.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/ru/ulstu/service/MethodParamBruteForce.java b/src/main/java/ru/ulstu/service/MethodParamBruteForce.java index 57a31b5..38cdc2a 100644 --- a/src/main/java/ru/ulstu/service/MethodParamBruteForce.java +++ b/src/main/java/ru/ulstu/service/MethodParamBruteForce.java @@ -33,7 +33,8 @@ class MethodParamBruteForce { private final int DEFAULT_THREAD_COUNT = 50; private final List methods; private final ScoreMethod scoreMethod = new Smape(); - private final ExecutorService executors = Executors.newFixedThreadPool(DEFAULT_THREAD_COUNT); + private final ExecutorService executors = Executors.newCachedThreadPool(); + ; public MethodParamBruteForce(List methods) { this.methods = methods; @@ -74,7 +75,7 @@ class MethodParamBruteForce { for (Future futureModelingResult : futureModelingResults) { modelingResults.add(futureModelingResult.get()); } - + System.gc(); return getBestResultForecast(modelingResults, timeSeries, countPoints); } @@ -159,6 +160,7 @@ class MethodParamBruteForce { for (Future futureModelingResult : results) { results2.add(futureModelingResult.get()); } + System.gc(); return results2.stream() .min(Comparator.comparing(modelingResult -> modelingResult.getScore().getDoubleValue())) .orElse(null); @@ -189,6 +191,7 @@ class MethodParamBruteForce { for (Future futureModelingResult : results) { results2.add(futureModelingResult.get()); } + System.gc(); return results2.stream() .min(Comparator.comparing(modelingResult -> modelingResult.getScore().getDoubleValue())) .orElse(null);