You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2019/07/22 14:13:52 UTC
[camel] branch master updated: camel-caffeine-lrucache: wrap
default executor to make it AOT friendly
This is an automated email from the ASF dual-hosted git repository.
lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new fc0e4ab camel-caffeine-lrucache: wrap default executor to make it AOT friendly
fc0e4ab is described below
commit fc0e4ab2e48ccf3224cc196fc7c045bab0a32608
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Mon Jul 22 16:05:51 2019 +0200
camel-caffeine-lrucache: wrap default executor to make it AOT friendly
---
.../component/caffeine/lrucache/CaffeineLRUCache.java | 14 ++++++++++++++
.../component/caffeine/lrucache/CaffeineLRUSoftCache.java | 4 ++--
.../component/caffeine/lrucache/CaffeineLRUWeakCache.java | 4 ++--
3 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/core/camel-caffeine-lrucache/src/main/java/org/apache/camel/component/caffeine/lrucache/CaffeineLRUCache.java b/core/camel-caffeine-lrucache/src/main/java/org/apache/camel/component/caffeine/lrucache/CaffeineLRUCache.java
index 14e8de6..a246dd7 100644
--- a/core/camel-caffeine-lrucache/src/main/java/org/apache/camel/component/caffeine/lrucache/CaffeineLRUCache.java
+++ b/core/camel-caffeine-lrucache/src/main/java/org/apache/camel/component/caffeine/lrucache/CaffeineLRUCache.java
@@ -21,6 +21,7 @@ import java.util.Collection;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
+import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.atomic.LongAdder;
import java.util.function.Consumer;
@@ -133,6 +134,7 @@ public class CaffeineLRUCache<K, V> implements LRUCache<K, V>, RemovalListener<K
.initialCapacity(initialCapacity)
.maximumSize(maximumCacheSize)
.removalListener(this);
+
if (soft) {
caffeine.softValues();
}
@@ -142,6 +144,18 @@ public class CaffeineLRUCache<K, V> implements LRUCache<K, V>, RemovalListener<K
}
if (syncListener) {
caffeine.executor(Runnable::run);
+ } else {
+ //
+ // by default, caffeine uses {@link ForkJoinPool#commonPool()} if an executor is not
+ // set which causes troubles in SubstrateVM as the common pool should be created at
+ // runtime.
+ //
+ // https://github.com/quarkusio/quarkus/issues/3300
+ //
+ // As workaround we can wrap it so a reference to the commonPool is not retained by
+ // caffeine's classes.
+ //
+ caffeine.executor(task -> ForkJoinPool.commonPool().execute(task));
}
this.cache = caffeine.build();
diff --git a/core/camel-caffeine-lrucache/src/main/java/org/apache/camel/component/caffeine/lrucache/CaffeineLRUSoftCache.java b/core/camel-caffeine-lrucache/src/main/java/org/apache/camel/component/caffeine/lrucache/CaffeineLRUSoftCache.java
index f466611..78180a7 100644
--- a/core/camel-caffeine-lrucache/src/main/java/org/apache/camel/component/caffeine/lrucache/CaffeineLRUSoftCache.java
+++ b/core/camel-caffeine-lrucache/src/main/java/org/apache/camel/component/caffeine/lrucache/CaffeineLRUSoftCache.java
@@ -47,9 +47,9 @@ import org.apache.camel.util.ObjectHelper;
* Notice that if the JVM reclaims memory, the content of this cache may be garbage collected without any
* eviction notifications.
* <p/>
- * Use {@link LRUCacheFactory} to create a new instance (do not use the constructor).
+ * Use {@link org.apache.camel.support.LRUCacheFactory} to create a new instance (do not use the constructor).
*
- * @see LRUCacheFactory
+ * @see org.apache.camel.support.LRUCacheFactory
* @see CaffeineLRUCache
* @see CaffeineLRUWeakCache
*/
diff --git a/core/camel-caffeine-lrucache/src/main/java/org/apache/camel/component/caffeine/lrucache/CaffeineLRUWeakCache.java b/core/camel-caffeine-lrucache/src/main/java/org/apache/camel/component/caffeine/lrucache/CaffeineLRUWeakCache.java
index c5016f6..ca6649f 100644
--- a/core/camel-caffeine-lrucache/src/main/java/org/apache/camel/component/caffeine/lrucache/CaffeineLRUWeakCache.java
+++ b/core/camel-caffeine-lrucache/src/main/java/org/apache/camel/component/caffeine/lrucache/CaffeineLRUWeakCache.java
@@ -47,9 +47,9 @@ import org.apache.camel.util.ObjectHelper;
* Notice that if the JVM reclaim memory the content of this cache may be garbage collected, without any
* eviction notifications.
* <p/>
- * Use {@link LRUCacheFactory} to create a new instance (do not use the constructor).
+ * Use {@link org.apache.camel.support.LRUCacheFactory} to create a new instance (do not use the constructor).
*
- * @see LRUCacheFactory
+ * @see org.apache.camel.support.LRUCacheFactory
* @see CaffeineLRUCache
* @see CaffeineLRUSoftCache
*/