From 5ef8ba12e971d922230df41893c571e0d46ca4ed Mon Sep 17 00:00:00 2001 From: oblonski Date: Thu, 29 Sep 2016 12:52:10 +0200 Subject: [PATCH] move hook stuff to if - related to #282 --- .../jsprit/core/algorithm/box/Jsprit.java | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/box/Jsprit.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/box/Jsprit.java index 0ada8a96..83551cc5 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/box/Jsprit.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/box/Jsprit.java @@ -619,33 +619,36 @@ public class Jsprit { private void handleExecutorShutdown(VehicleRoutingAlgorithm vra) { if (setupExecutorInternally) { - vra.addListener(new AlgorithmEndsListener() { - - @Override - public void informAlgorithmEnds(VehicleRoutingProblem problem, Collection solutions) { - es.shutdown(); - } - - }); - } - if (es != null) { final Thread hook = new Thread() { public void run() { if (!es.isShutdown()) { - System.err.println("shutdowHook shuts down executorService"); + System.err.println("shutdownHook shuts down executorService"); es.shutdown(); } } }; Runtime.getRuntime().addShutdownHook(hook); vra.addListener(new AlgorithmEndsListener() { + @Override - public void informAlgorithmEnds(VehicleRoutingProblem aProblem, - Collection aSolutions) { + public void informAlgorithmEnds(VehicleRoutingProblem problem, Collection solutions) { + es.shutdown(); Runtime.getRuntime().removeShutdownHook(hook); } + }); } +// if (es != null) { +// +// Runtime.getRuntime().addShutdownHook(hook); +// vra.addListener(new AlgorithmEndsListener() { +// @Override +// public void informAlgorithmEnds(VehicleRoutingProblem aProblem, +// Collection aSolutions) { +// Runtime.getRuntime().removeShutdownHook(hook); +// } +// }); +// } } String getProperty(String key) {