I'm currently working on a program to run externally supplied code by the user (assume this case is justified). After a lot of research, I've found that most of the security involved with this can be handled by a SecurityManager; however, I'm struggling to find a way to kill the external code if it's taking too long and intending to be malicious. For example, if the external code looked like:
while (true) {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
// Oh well, keep running
}
}
This would keep running forever, and Thread.interrupt() wouldn't do anything to stop the thread. Is there another method to stop a rogue thread that won't cause any issues? All I've come across is Thread.stop() however it doesn't seem to be an option with all the issues that seem to come with it. If not, are there other options available to run this code in a way that the program will still be able to interface with it directly?