如何了解哪些调用在 CompletionService 中抛出异常?

问题描述

我正在并行调用一些方法。如果任何方法抛出异常,我想使用传递给方法的值。

PS:请忽略任何语法错误

 public static void main() {
     Executor executor = Executors.newFixedThreadPool(3);
     CompletionService<SomeResult> executorCompletionService = new ExecutorCompletionService<SomeResult>(executor);
     List<Future<Integer>> futures = new ArrayList<>();

     futures.add(executorCompletionService.submit(() -> someMethod(parameterValueForFirstCall)));
     futures.add(executorCompletionService.submit(() -> someMethod(parameterValueForSecondCall)));
     futures.add(executorCompletionService.submit(() -> someMethod(parameterValueForThirdCall)));

     for (int i=0; i<3; i++){

        try {
            executorCompletionService.take().get();       
        } catch(Exception e) {
         System.out.println("exception caught :" + e.getMessage());
         //do something with parameter passed to method that threw exception
     }
 }

解决方法

类似的东西?

const useStyles = makeStyles((theme) => ({
    h2 : {
            width: '100%',textAlign: 'center',borderBottom: '1px solid #000',lineHeight: '0.1em',margin: '10px 0 20px',},h2 span: { 
             background:'#fff',padding:'0 10px',}
}))