-1

代码 :

Class Manager {
    Future  fu  = pool.invokeAll(workers, SEARCH_TIMEOUT, TimeUnit.SECONDS); 
    // calling the invoke call 
    search search= fu.get();    
   // callable 
}


public class Search implements Callable<Search> {
    Search call() {
        // multiple workers will execute Code So don't want to catch timed out exception in here 
        // api value will be changing based on corresponding reference 
        api.search_api();
    }
}


class api()
{
    search_api(){
        // How to catch a timed out exception in here 
        // catch(TimedoutException){}    did not work in here 
    }
}

有没有办法可以在方法下的 Class api 中捕获 TimedOut 异常search_api()

4

2 回答 2

1

您可以像以下代码一样捕获TimeoutException :

try {
        Future fu = pool.invokeAll(workers, SEARCH_TIMEOUT,
                TimeUnit.SECONDS);
        // calling the invoke call
        search search = fu.get();
    } catch (TimeoutException e) {
        e.printStackTrace();
    }
于 2012-08-06T03:57:51.107 回答
0

您也可以通过以下方式进行

try{

.

.

.

.


catch (RuntimeException e) {
        // TODO: handle exception
}   
于 2012-08-06T04:41:07.617 回答