If the method call takes more than 10 seconds I want to kill it and move on.
Is multi-threading my only option to solve this problem?
If I go with multi-threading which I'm very new at, my run method would only contain the one method as follows. If myMethod() gets stuck in an infinite loop is there a way to interrupt this thread?
public void run() {
myMethod();
}
Let's assume myMethod() is the following and changing it is not an option.
while(true){
System.out.println("Thinking.");
for (int i = 0; i < 100000; i++) {
//wasting time
}
}
I was going for Mik378's solution, but I don't think this will work as myMethod doesn't throw the InterruptedException exception.