1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00

move hook stuff to if - related to #282

This commit is contained in:
oblonski 2016-09-29 12:52:10 +02:00
parent 915b2969a3
commit 5ef8ba12e9

View file

@ -619,33 +619,36 @@ public class Jsprit {
private void handleExecutorShutdown(VehicleRoutingAlgorithm vra) { private void handleExecutorShutdown(VehicleRoutingAlgorithm vra) {
if (setupExecutorInternally) { if (setupExecutorInternally) {
vra.addListener(new AlgorithmEndsListener() {
@Override
public void informAlgorithmEnds(VehicleRoutingProblem problem, Collection<VehicleRoutingProblemSolution> solutions) {
es.shutdown();
}
});
}
if (es != null) {
final Thread hook = new Thread() { final Thread hook = new Thread() {
public void run() { public void run() {
if (!es.isShutdown()) { if (!es.isShutdown()) {
System.err.println("shutdowHook shuts down executorService"); System.err.println("shutdownHook shuts down executorService");
es.shutdown(); es.shutdown();
} }
} }
}; };
Runtime.getRuntime().addShutdownHook(hook); Runtime.getRuntime().addShutdownHook(hook);
vra.addListener(new AlgorithmEndsListener() { vra.addListener(new AlgorithmEndsListener() {
@Override @Override
public void informAlgorithmEnds(VehicleRoutingProblem aProblem, public void informAlgorithmEnds(VehicleRoutingProblem problem, Collection<VehicleRoutingProblemSolution> solutions) {
Collection<VehicleRoutingProblemSolution> aSolutions) { es.shutdown();
Runtime.getRuntime().removeShutdownHook(hook); Runtime.getRuntime().removeShutdownHook(hook);
} }
}); });
} }
// if (es != null) {
//
// Runtime.getRuntime().addShutdownHook(hook);
// vra.addListener(new AlgorithmEndsListener() {
// @Override
// public void informAlgorithmEnds(VehicleRoutingProblem aProblem,
// Collection<VehicleRoutingProblemSolution> aSolutions) {
// Runtime.getRuntime().removeShutdownHook(hook);
// }
// });
// }
} }
String getProperty(String key) { String getProperty(String key) {