Cancelling on thread interruption

Hi,

I am playing around with the open source version of the Isochrone extension to Graphhopper. In my implementation, I want to be able to cancel the operation after a specific timeout (i.e. 60 sec). I’ve set up the handler similar to the example in the we bundle (https://github.com/graphhopper/graphhopper/blob/master/web-bundle/src/main/java/com/graphhopper/resources/IsochroneResource.java).

If I run this as a Callable with a timeout, I do get a timeout exception, but the calculation will proceed until finished (it is the calcList method in the DelaunayTriangulationIsolineBuilder class that take time). I’d want the process to be cancelled when the Thread gets interrupted and free resources.

Checking if the thread is interrupted in the loops of the calcList method could be one solution, i.e.
for (int i = 0; i < pointsList.size(); i++) { ... if (Thread.currentThread().isInterrupted()) { throw new RuntimeException("Thread interrupted"); } }

I could also set the “maxVisitedNodes” for the Graphhopper instance and stop there, but then I loose the timeout perspective.

Is there any other way I could set a timeout?

Thanks