future, long timeout, TimeUnit unit) {
+ try {
+ return future.get(timeout, unit);
+ } catch (TimeoutException e) {
+ throw new ConcurrentException("Timeout:wait " + timeout + unit.name(), e);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new ConcurrentException("Interrupted", e);
+ } catch (ExecutionException e) {
+ throw new ConcurrentException(e.getMessage(), e.getCause());
+ }
+ }
+
/**
* 等待所有任务完成(无时间限制)
*
@@ -49,8 +85,11 @@ public static void awaitAll(Future>[] futures, int start) {
future.get();
}
}
- } catch (InterruptedException | ExecutionException e) {
- throw new ConcurrentException(e);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new ConcurrentException("Interrupted", e);
+ } catch (ExecutionException e) {
+ throw new ConcurrentException(e.getMessage(), e.getCause());
}
}
@@ -83,8 +122,11 @@ public static void awaitAll(ArrayList> futures, int start) {
future.get();
}
}
- } catch (InterruptedException | ExecutionException e) {
- throw new ConcurrentException(e);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new ConcurrentException("Interrupted", e);
+ } catch (ExecutionException e) {
+ throw new ConcurrentException(e.getMessage(), e.getCause());
}
}
@@ -135,8 +177,11 @@ public static int awaitAll(Future>[] futures, long timeout, TimeUnit unit, int
return i;
} catch (TimeoutException e) {
return i;
- } catch (Exception e) {
- throw new ConcurrentException(e);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new ConcurrentException("Interrupted", e);
+ } catch (ExecutionException e) {
+ throw new ConcurrentException(e.getMessage(), e.getCause());
}
}
@@ -186,8 +231,11 @@ public static int awaitAll(ArrayList> futures, long timeout, TimeUnit
return i;
} catch (TimeoutException e) {
return i;
- } catch (Exception e) {
- throw new ConcurrentException(e);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new ConcurrentException("Interrupted", e);
+ } catch (ExecutionException e) {
+ throw new ConcurrentException(e.getMessage(), e.getCause());
}
}