We run an AI
programming competition in which contestants will code an AI
that runs on the JVM
using our API
we provide them. We put them into a sandbox by limiting what they can do with a SecurityManager
, and during runtime they simply set several flags which are their decisions. The only interaction between our system and their AI
is through these flags, so there are no bad effects on us if their thread were to suddenly die.
When an AI
computes far too long, we would like to shut down their thread. However, we can't find a way of guaranteeing that we will destroy their thread. One possible reason for this is that the AI
goes into an infinite loop with no blocking, making Thread.interrupt()
useless. Thread.stop()
is unreliable since if they are in a try catch block the ThreadDeath
exception will be caught, and has no issues for us because they don't touch anything bad and we don't care if they die.
Currently we just ignore their thread and continue on without them after they time out, but their infinite loop will continue processing in the background until the JVM
dies. This is unacceptable to us because we will be running matches in the background on a web server 24/7, so we want as much stability as possible. One thought has been to run each game in a separate JVM
, but that is far more complex than we would like to get.
Is there any sure fire way to destroy the thread?