You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2018/10/29 13:28:30 UTC
[isis] branch v2 updated: ISIS-1811: when creating
CompletableFuture use ForkJoinPool instead of fixed ThreadPool
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch v2
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/v2 by this push:
new 3040c3f ISIS-1811: when creating CompletableFuture use ForkJoinPool instead of fixed ThreadPool
3040c3f is described below
commit 3040c3f0d0187e25159a54dc9580b4f21f39e752
Author: Andi Huber <ah...@apache.org>
AuthorDate: Mon Oct 29 14:28:15 2018 +0100
ISIS-1811: when creating CompletableFuture use ForkJoinPool instead of
fixed ThreadPool
ThreadPoolSupport does not allow to utilize InheritableThreadLocal
variables, but ForkJoinPool does.
---
.../isis/core/runtime/threadpool/ThreadPoolSupport.java | 3 ++-
.../isis/core/runtime/system/context/IsisContext.java | 17 ++++++-----------
.../core/runtime/system/session/IsisSessionFactory.java | 8 +++++++-
3 files changed, 15 insertions(+), 13 deletions(-)
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/runtime/threadpool/ThreadPoolSupport.java b/core/metamodel/src/main/java/org/apache/isis/core/runtime/threadpool/ThreadPoolSupport.java
index 35be70b..7f18d12 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/runtime/threadpool/ThreadPoolSupport.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/runtime/threadpool/ThreadPoolSupport.java
@@ -116,7 +116,8 @@ public final class ThreadPoolSupport implements AutoCloseable {
/**
* Non-blocking call.
* <p>
- * If the computation requires an IsisSession use {@code IsisContext.newCompletableFuture(Supplier)} instead.
+ * If the computation requires an open IsisSession use {@code IsisContext.compute(Supplier)} instead,
+ * which utilizes a ForkJoinPool instead.
*
* @param computation - async task
* @return new CompletableFuture utilizing this thread-pool's underlying concurrent executor
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/context/IsisContext.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/context/IsisContext.java
index ed26bf8..83c3711 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/context/IsisContext.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/context/IsisContext.java
@@ -35,7 +35,6 @@ import org.apache.isis.core.runtime.system.DeploymentType;
import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
import org.apache.isis.core.runtime.system.session.IsisSession;
import org.apache.isis.core.runtime.system.session.IsisSessionFactory;
-import org.apache.isis.core.runtime.threadpool.ThreadPoolSupport;
/**
* Provides static access to current context's singletons
@@ -75,20 +74,16 @@ public interface IsisContext {
/**
* Non-blocking call.
* <p>
- * Utilizes the framework's thread pool by submitting the specified {@code computation} to run
- * in background. The {@code computation} is running in the context of a new {@link IsisSession}.
+ * Returns a new CompletableFuture that is asynchronously completed by a task running in the
+ * ForkJoinPool.commonPool() with the value obtained by calling the given Supplier {@code computation}.
* <p>
- * If the computation requires no IsisSession use
- * {@link ThreadPoolSupport#newCompletableFuture(Supplier)} instead.
+ * If the calling thread is within an open {@link IsisSession} then the ForkJoinPool does make this
+ * session also available for any forked threads, via means of {@link InheritableThreadLocal}.
*
* @param computation
- * @return
*/
- public static <T> CompletableFuture<T> newCompletableFuture(Supplier<T> computation){
- final Supplier<T> computationWithSession = ()->
- IsisContext.getSessionFactory().doInSession(computation::get);
-
- return ThreadPoolSupport.getInstance().newCompletableFuture(computationWithSession);
+ public static <T> CompletableFuture<T> compute(Supplier<T> computation){
+ return CompletableFuture.supplyAsync(computation);
}
/**
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactory.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactory.java
index 1e55730..e295896 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactory.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactory.java
@@ -48,6 +48,7 @@ import org.apache.isis.core.runtime.authorization.AuthorizationManager;
import org.apache.isis.core.runtime.fixtures.FixturesInstallerFromConfiguration;
import org.apache.isis.core.runtime.system.DeploymentType;
import org.apache.isis.core.runtime.system.MessageRegistry;
+import org.apache.isis.core.runtime.system.context.IsisContext;
import org.apache.isis.core.runtime.system.internal.InitialisationSession;
import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
import org.apache.isis.core.runtime.system.persistence.PersistenceSessionFactory;
@@ -251,7 +252,12 @@ implements ApplicationScopedComponent, AppManifestProvider {
}
// -- openSession, closeSession, currentSession, inSession
- private final ThreadLocal<IsisSession> currentSession = new ThreadLocal<>();
+
+ /**
+ * Inheritable... allows to have concurrent computations utilizing the ForkJoinPool.
+ * see {@link IsisContext#compute(java.util.function.Supplier)}
+ */
+ private final InheritableThreadLocal<IsisSession> currentSession = new InheritableThreadLocal<>();
/**
* Creates and {@link IsisSession#open() open}s the {@link IsisSession}.