Skip to content

Commit ae774e9

Browse files
authored
Merge pull request #38 from patricklaux/dev
1.2.1
2 parents 20f817c + 3dacb23 commit ae774e9

File tree

4 files changed

+67
-15
lines changed

4 files changed

+67
-15
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ xtool 是一个小小的 Java 工具集,遵循简单、可靠的原则,不
2020
<dependency>
2121
<groupId>com.igeeksky.xtool</groupId>
2222
<artifactId>xtool</artifactId>
23-
<version>1.2.0</version>
23+
<version>1.2.1</version>
2424
</dependency>
2525
```
2626

2727
### 2.2.Gradle
2828

2929
```groovy
30-
implementation group: 'com.igeeksky.xtool', name: 'xtool', version: '1.2.0'
30+
implementation group: 'com.igeeksky.xtool', name: 'xtool', version: '1.2.1'
3131
```
3232

3333
### 2.3.编译安装
@@ -82,7 +82,11 @@ mvn clean install
8282

8383
### 1.2.0
8484

85-
* 调整 Futures 接口参数
85+
* `Futures` InterruptedException: interrupt currentThread
86+
87+
### 1.2.0
88+
89+
* change `Futures` API params
8690

8791
### 1.1.3
8892

docs/Reference.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## xtool 参考文档
22

3-
Author: [Patrick.Lau](mailto:[email protected]) Version: 1.2.0
3+
Author: [Patrick.Lau](mailto:[email protected]) Version: 1.2.1
44

55
[![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html) [![Release](https://img.shields.io/github/v/release/patricklaux/xtool)](https://github.com/patricklaux/xtool/releases) [![Maven Central](https://img.shields.io/maven-central/v/com.igeeksky.xtool/xtool.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.igeeksky.xtool%22%20AND%20a:%22xtool%22) [![codecov](https://codecov.io/gh/patricklaux/xtool/branch/main/graph/badge.svg?token=VJ87A1IAVH)](https://codecov.io/gh/patricklaux/xtool) [![Last commit](https://img.shields.io/github/last-commit/patricklaux/xtool)](https://github.com/patricklaux/xtool/commits) [![Join the chat at https://gitter.im/igeeksky/xtool](https://badges.gitter.im/igeeksky/xtool.svg)](https://gitter.im/igeeksky/xtool?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
66

@@ -26,14 +26,14 @@ xtool 是一个小小的 Java 工具集,遵循简单、可靠的原则,不
2626
<dependency>
2727
<groupId>com.igeeksky.xtool</groupId>
2828
<artifactId>xtool</artifactId>
29-
<version>1.2.0</version>
29+
<version>1.2.1</version>
3030
</dependency>
3131
```
3232

3333
#### 1.2.2.Gradle
3434

3535
```groovy
36-
implementation group: 'com.igeeksky.xtool', name: 'xtool', version: '1.2.0'
36+
implementation group: 'com.igeeksky.xtool', name: 'xtool', version: '1.2.1'
3737
```
3838

3939
#### 1.2.3.编译安装

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.igeeksky.xtool</groupId>
88
<artifactId>xtool</artifactId>
9-
<version>1.2.0</version>
9+
<version>1.2.1</version>
1010
<name>xtool</name>
1111
<description>xtool is a very small set of Java tools.</description>
1212
<url>https://github.com/patricklaux/xtool</url>

src/main/java/com/igeeksky/xtool/core/concurrent/Futures.java

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,42 @@ public final class Futures {
2020
private Futures() {
2121
}
2222

23+
/**
24+
* 等待任务完成并返回任务执行结果(无时间限制)
25+
*
26+
* @param future 任务
27+
* @return 任务执行结果
28+
*/
29+
public static <T> T await(Future<T> future) {
30+
try {
31+
return future.get();
32+
} catch (InterruptedException e) {
33+
Thread.currentThread().interrupt();
34+
throw new ConcurrentException("Interrupted", e);
35+
} catch (ExecutionException e) {
36+
throw new ConcurrentException(e.getMessage(), e.getCause());
37+
}
38+
}
39+
40+
/**
41+
* 等待任务完成并返回任务执行结果(无时间限制)
42+
*
43+
* @param future 任务
44+
* @return 任务执行结果
45+
*/
46+
public static <T> T await(Future<T> future, long timeout, TimeUnit unit) {
47+
try {
48+
return future.get(timeout, unit);
49+
} catch (TimeoutException e) {
50+
throw new ConcurrentException("Timeout:wait " + timeout + unit.name(), e);
51+
} catch (InterruptedException e) {
52+
Thread.currentThread().interrupt();
53+
throw new ConcurrentException("Interrupted", e);
54+
} catch (ExecutionException e) {
55+
throw new ConcurrentException(e.getMessage(), e.getCause());
56+
}
57+
}
58+
2359
/**
2460
* 等待所有任务完成(无时间限制)
2561
* <p>
@@ -49,8 +85,11 @@ public static void awaitAll(Future<?>[] futures, int start) {
4985
future.get();
5086
}
5187
}
52-
} catch (InterruptedException | ExecutionException e) {
53-
throw new ConcurrentException(e);
88+
} catch (InterruptedException e) {
89+
Thread.currentThread().interrupt();
90+
throw new ConcurrentException("Interrupted", e);
91+
} catch (ExecutionException e) {
92+
throw new ConcurrentException(e.getMessage(), e.getCause());
5493
}
5594
}
5695

@@ -83,8 +122,11 @@ public static void awaitAll(ArrayList<Future<?>> futures, int start) {
83122
future.get();
84123
}
85124
}
86-
} catch (InterruptedException | ExecutionException e) {
87-
throw new ConcurrentException(e);
125+
} catch (InterruptedException e) {
126+
Thread.currentThread().interrupt();
127+
throw new ConcurrentException("Interrupted", e);
128+
} catch (ExecutionException e) {
129+
throw new ConcurrentException(e.getMessage(), e.getCause());
88130
}
89131
}
90132

@@ -135,8 +177,11 @@ public static int awaitAll(Future<?>[] futures, long timeout, TimeUnit unit, int
135177
return i;
136178
} catch (TimeoutException e) {
137179
return i;
138-
} catch (Exception e) {
139-
throw new ConcurrentException(e);
180+
} catch (InterruptedException e) {
181+
Thread.currentThread().interrupt();
182+
throw new ConcurrentException("Interrupted", e);
183+
} catch (ExecutionException e) {
184+
throw new ConcurrentException(e.getMessage(), e.getCause());
140185
}
141186
}
142187

@@ -186,8 +231,11 @@ public static int awaitAll(ArrayList<Future<?>> futures, long timeout, TimeUnit
186231
return i;
187232
} catch (TimeoutException e) {
188233
return i;
189-
} catch (Exception e) {
190-
throw new ConcurrentException(e);
234+
} catch (InterruptedException e) {
235+
Thread.currentThread().interrupt();
236+
throw new ConcurrentException("Interrupted", e);
237+
} catch (ExecutionException e) {
238+
throw new ConcurrentException(e.getMessage(), e.getCause());
191239
}
192240
}
193241

0 commit comments

Comments
 (0)