Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can infinite loops be terminated in dynamically loaded classes?

Tags:

java

I wrote a program that automatically grades programming assignments submitted from students. Reflection is used to load classes and instantiate objects. Unintentional infinite loops are a common mistake in student assignments. A thread is assigned to each student submission. A monitor keeps track of the threads' running time and uses the stop() method to terminate threads that exceed the maximum time allowed. My program is working as intended, but the stop() method in java.lang.Thread is deprecated. I would greatly appreciate advice on a cleaner solution.

Thank you.

like image 390
Jenks Avatar asked Nov 26 '14 22:11

Jenks


1 Answers

stop() in java.lang.Thread was deprecated for good reasons: it didn't always work and could interfere with the workings of the JVM.

Your best bet is to run the programs in separate JVMs. You can then kill the processes if you need to.

like image 61
Bathsheba Avatar answered Oct 25 '22 06:10

Bathsheba