如何运行超时方法?

时间:2014-11-10 10:47:34

标签: java multithreading spring concurrency

我想用超时执行一个特定的方法。只要超时方法仍在运行,包装器方法就应该阻塞。

我怎样才能最好地实现这一点,最好使用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
}

0 个答案:

没有答案