stop a thread in java after a given time - doesn't work

后端 未结 5 544
清酒与你
清酒与你 2021-01-25 04:06

I have a complex function (optimisation) that can potentially enter in a loop or just to take too much time, and the time allowed is set by the user.

Therefore I am tryi

5条回答
  •  猫巷女王i
    2021-01-25 04:49

    Watchdog-Timers in Java are not a simple thing, since threading is cooperative. I remember that in one project we just used Thread.stop() although it is deprecated, but there was no elegant solution. We didn't face any issues using it, though.

    A good example for a Java Watchdog implementation:

    http://everything2.com/user/Pyrogenic/writeups/Watchdog+timer

提交回复
热议问题