I use Jython as a scripting engine for Java program. Needless to say, nasty bugs can enter the user scripts to introduce things like infinite loops etc. If such errors bring down the whole system that's not reasonable.

I'd like to measure the code execution time and terminate the execution if the execution takes suspiciously long time. One approach could be running the Jython interpreter in a separate thread and violently stop that thread if such need occurs. But that feels brutal.

Perhaps there's a better method?

Pavils Jurjans