You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/03/20 17:49:14 UTC
[commons-lang] branch master updated: Use Java 8 API ConcurrentMap#computeIfAbsent().
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git
The following commit(s) were added to refs/heads/master by this push:
new cb6676b Use Java 8 API ConcurrentMap#computeIfAbsent().
cb6676b is described below
commit cb6676b1bbafbb46b68b864eb9d6cfbc5d5dac99
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Mar 20 13:49:09 2022 -0400
Use Java 8 API ConcurrentMap#computeIfAbsent().
---
.../java/org/apache/commons/lang3/concurrent/Memoizer.java | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/src/main/java/org/apache/commons/lang3/concurrent/Memoizer.java b/src/main/java/org/apache/commons/lang3/concurrent/Memoizer.java
index 4dacac0..ab3feea 100644
--- a/src/main/java/org/apache/commons/lang3/concurrent/Memoizer.java
+++ b/src/main/java/org/apache/commons/lang3/concurrent/Memoizer.java
@@ -112,16 +112,11 @@ public class Memoizer<I, O> implements Computable<I, O> {
@Override
public O compute(final I arg) throws InterruptedException {
while (true) {
- Future<O> future = cache.get(arg);
- if (future == null) {
+ Future<O> future = cache.computeIfAbsent(arg, k -> {
final FutureTask<O> futureTask = new FutureTask<>(() -> computable.compute(arg));
- future = cache.putIfAbsent(arg, futureTask);
- if (future == null) {
- future = futureTask;
- futureTask.run();
- }
- }
-
+ futureTask.run();
+ return futureTask;
+ });
try {
return future.get();
} catch (final CancellationException e) {