我想用超时执行一个特定的方法。只要超时方法仍在运行,包装器方法就应该阻塞。
我怎样才能最好地实现这一点,最好使用Spring
?
public boolean run() {
long start = System.currentTimeMillis();
try {
executeWithTimeout(); //how?
} catch (TimeoutException e) {
long end = System.currentTimeMillis();
log.info("method could not complete");
return false;
}
return true; //block as long as the method above is still running
}