在 Callable 中处理 Thread.interrupted() 的正确方法是什么?我猜这个callable应该抛出一个InterruptedException;例如:
public class MyCallable implements Callable<Object> {
public Object call() {
Object result = null;
// Simulate long-running operation that calculates result
while (true) {
...
if (Thread.interrupted()) {
throw new InterruptedException();
}
}
result = ... // something produced by the long-running operation
return result;
}
}
这是正确的,还是有更合适的方法来处理它?谢谢。