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) {
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() {
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<VehicleRoutingProblemSolution> aSolutions) {
public void informAlgorithmEnds(VehicleRoutingProblem problem, Collection<VehicleRoutingProblemSolution> 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<VehicleRoutingProblemSolution> aSolutions) {
// Runtime.getRuntime().removeShutdownHook(hook);
// }
// });
// }
}
String getProperty(String key) {