mercredi 15 janvier 2020

How to stop a java method early? [duplicate]

I have a java method running the A* pathfinding algorithm. I would like to stop the method after 30 seconds has elapsed, if the method has not already finished. Upon Finishing I would like it to return its data structures it was using (in both cases where it finishes naturally and when it passes the time limit). I can not poll for exit in the algorithm because I am trying to compare it to other algorithms and the extra check would distort results a little if I poll more in one algorithm than another.

I have tried using threading, but I cannot seem to stop the execution early and return something, I have tried googles guava SimpleTimeLimiter, but this too seems like it does not stop execution of the method we are limiting time to.

Aucun commentaire:

Enregistrer un commentaire