My program is fairly large, and because it tends to carry out processes randomly, at times it gets stuck and loops forever. If I were to forcefully stop and restart the program manually, usually (around 85%) of the time, the program completes all commands and terminates.
Is there a way to make a Java program restart itself after say 20 seconds, if it gets stuck? I tried using the system time to solve the issue, but the problem with this is that if my program gets stuck in a for loop, it does not update the system time until the next iteration.
This isn't the right way to approach this problem! You need to figure out why your program is getting stuck in an infinite loop, and then fix it. "Okay let's try this again" is not the right way to solve a bug - you have no idea what other effects this bug could be having. You might very well be getting incorrect output as well. Debug the program, don't work around the flaw.
You could use some external program that launches the java program and kills it after 20 seconds when it gets stuck, and then launches it again, but again, that is not the right way to solve the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With