2012-08-06 3 views
-1

code:Comment attraper Timed Out Exception

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 
    } 
} 

Est-il possible que je puisse attraper l'exception TimedOut dans la api de classe selon la méthode search_api()?

Répondre

1

Vous pouvez prendre TimeoutException comme ce code:

try { 
     Future fu = pool.invokeAll(workers, SEARCH_TIMEOUT, 
       TimeUnit.SECONDS); 
     // calling the invoke call 
     search search = fu.get(); 
    } catch (TimeoutException e) { 
     e.printStackTrace(); 
    } 
0

Vous pouvez aussi le faire par la manière suivante

try{ 

. 

. 

. 

. 


catch (RuntimeException e) { 
     // TODO: handle exception 
}