Skip to content

Commit 7abfad8

Browse files
committed
Fix concurrency issue in AsyncCompletions; fix hashCodes in ReferenceTypes; prepare next build
1 parent d85ff52 commit 7abfad8

File tree

4 files changed

+25
-25
lines changed

4 files changed

+25
-25
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Maven Central](https://img.shields.io/maven-central/v/net.tascalate/net.tascalate.concurrent.svg)](https://search.maven.org/artifact/net.tascalate/net.tascalate.concurrent/0.9.9/jar) [![GitHub release](https://img.shields.io/github/release/vsilaev/tascalate-concurrent.svg)](https://github.com/vsilaev/tascalate-concurrent/releases/tag/0.9.9) [![license](https://img.shields.io/github/license/vsilaev/tascalate-concurrent.svg)](http://www.apache.org/licenses/LICENSE-2.0.txt)
1+
[![Maven Central](https://img.shields.io/maven-central/v/net.tascalate/net.tascalate.concurrent.svg)](https://search.maven.org/artifact/net.tascalate/net.tascalate.concurrent/0.9.10/jar) [![GitHub release](https://img.shields.io/github/release/vsilaev/tascalate-concurrent.svg)](https://github.com/vsilaev/tascalate-concurrent/releases/tag/0.9.10) [![license](https://img.shields.io/github/license/vsilaev/tascalate-concurrent.svg)](http://www.apache.org/licenses/LICENSE-2.0.txt)
22
# tascalate-concurrent
33
The library provides an implementation of the [CompletionStage](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletionStage.html) interface and related classes these are designed to support long-running blocking tasks (typically, I/O bound). This functionality augments the sole Java 8 built-in implementation, [CompletableFuture](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html), that is primarily supports computational tasks. Also, the library helps with numerous asynchronous programing challenges like handling timeouts, retry/poll functionality, orchestrating results of multiple concurrent computations and similar.
44

@@ -12,7 +12,7 @@ New name:
1212
<dependency>
1313
<groupId>net.tascalate</groupId>
1414
<artifactId>net.tascalate.concurrent</artifactId>
15-
<version>0.9.9</version> <!-- Any version above 0.8.0, the latest one is recommended -->
15+
<version>0.9.10</version> <!-- Any version above 0.8.0, the latest one is recommended -->
1616
</dependency>
1717
```
1818
Old Name
@@ -38,7 +38,7 @@ To use a library you have to add a single Maven dependency
3838
<dependency>
3939
<groupId>net.tascalate</groupId>
4040
<artifactId>net.tascalate.concurrent</artifactId>
41-
<version>0.9.9</version>
41+
<version>0.9.10</version>
4242
</dependency>
4343
```
4444

pom.xml

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

77
<groupId>net.tascalate</groupId>
88
<artifactId>net.tascalate.concurrent</artifactId>
9-
<version>0.9.9</version>
9+
<version>0.9.10</version>
1010
<packaging>jar</packaging>
1111

1212
<name>Tascalate Concurrent</name>

src/main/java/net/tascalate/concurrent/AsyncCompletions.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,20 @@ public T next() {
114114
} else {
115115
if (!settledResults.isEmpty()) {
116116
// There are some resolved results available
117-
return settledResults.poll().done();
117+
Try<T> settledResult = settledResults.poll();
118+
inProgress.decrementAndGet();
119+
return settledResult.done();
118120
} else {
119121
if (unprocessed > 0) {
120-
// If we are still producing then await for any result...
122+
// If we are still producing then await for any result...
123+
Try<T> settledResult;
121124
try {
122-
return settledResults.take().done();
125+
settledResult = settledResults.take();
123126
} catch (InterruptedException ex) {
124127
throw new NoSuchElementException(ex.getMessage());
125128
}
129+
inProgress.decrementAndGet();
130+
return settledResult.done();
126131
} else {
127132
if (enlistPending()) {
128133
// More was enlisted
@@ -221,23 +226,18 @@ private boolean enlistPending() {
221226
}
222227

223228
private BiConsumer<T, Throwable> enlistResolved(CompletionStage<? extends T> promise) {
224-
return (v, ex) -> {
229+
return (resolvedValue, ex) -> {
225230
enlistedPromises.remove(promise);
226-
enlistResolved(v, ex);
227-
};
228-
}
229-
230-
private void enlistResolved(T resolvedValue, Throwable ex) {
231-
try {
232-
if (ex == null) {
233-
settledResults.put(Try.success(resolvedValue));
234-
} else {
235-
settledResults.put(Try.failure(ex));
231+
try {
232+
if (ex == null) {
233+
settledResults.put(Try.success(resolvedValue));
234+
} else {
235+
settledResults.put(Try.failure(ex));
236+
}
237+
} catch (InterruptedException e) {
238+
throw new RuntimeException(e); // Shouldn't happen for the queue with an unlimited size
236239
}
237-
} catch (InterruptedException e) {
238-
throw new RuntimeException(e); // Shouldn't happen for the queue with an unlimited size
239-
}
240-
inProgress.decrementAndGet();
240+
};
241241
}
242242

243243
}

src/main/java/net/tascalate/concurrent/core/ReferenceType.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static final class LookupKey<K> {
9494

9595
LookupKey(K key) {
9696
this.key = key;
97-
this.hashCode = System.identityHashCode(key);
97+
this.hashCode = key == null ? 0 : key.hashCode();
9898
}
9999

100100
@Override
@@ -118,7 +118,7 @@ static final class WeakKey<K> extends WeakReference<K> {
118118

119119
WeakKey(K key, ReferenceQueue<? super K> queue) {
120120
super(key, queue);
121-
hashCode = System.identityHashCode(key);
121+
hashCode = key == null ? 0 : key.hashCode();
122122
}
123123

124124
@Override
@@ -147,7 +147,7 @@ static final class SoftKey<K> extends SoftReference<K> {
147147

148148
SoftKey(K key, ReferenceQueue<? super K> queue) {
149149
super(key, queue);
150-
hashCode = System.identityHashCode(key);
150+
hashCode = key == null ? 0 : key.hashCode();
151151
}
152152

153153
@Override

0 commit comments

Comments
 (0)