You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by pa...@apache.org on 2023/12/04 14:27:25 UTC
(sling-org-apache-sling-scripting-core) branch master updated: SLING-12057: Replace commons.threads with Executor and embed commons.compiler.source
This is an automated email from the ASF dual-hosted git repository.
pauls pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-core.git
The following commit(s) were added to refs/heads/master by this push:
new ef9e8d5 SLING-12057: Replace commons.threads with Executor and embed commons.compiler.source
ef9e8d5 is described below
commit ef9e8d55b2bda8e96c7716d9de1c3f2fc588d8da
Author: Karl Pauls <ka...@gmail.com>
AuthorDate: Mon Dec 4 15:07:57 2023 +0100
SLING-12057: Replace commons.threads with Executor and embed commons.compiler.source
---
bnd.bnd | 2 +-
.../sling/scripting/core/impl/ScriptCacheImpl.java | 18 +++++++++++-------
2 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/bnd.bnd b/bnd.bnd
index 80c64c7..20f9145 100644
--- a/bnd.bnd
+++ b/bnd.bnd
@@ -3,7 +3,7 @@ Import-Package:\
*
Conditional-Package:\
- org.apache.felix.utils.json.*
+ org.apache.felix.utils.json.*,org.apache.sling.commons.compiler.source.*
-exportcontents: ${packages;VERSIONED}
diff --git a/src/main/java/org/apache/sling/scripting/core/impl/ScriptCacheImpl.java b/src/main/java/org/apache/sling/scripting/core/impl/ScriptCacheImpl.java
index 579e11f..ae93f4a 100644
--- a/src/main/java/org/apache/sling/scripting/core/impl/ScriptCacheImpl.java
+++ b/src/main/java/org/apache/sling/scripting/core/impl/ScriptCacheImpl.java
@@ -27,6 +27,9 @@ import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
@@ -39,8 +42,6 @@ import org.apache.sling.api.resource.observation.ExternalResourceChangeListener;
import org.apache.sling.api.resource.observation.ResourceChange;
import org.apache.sling.api.resource.observation.ResourceChange.ChangeType;
import org.apache.sling.api.resource.observation.ResourceChangeListener;
-import org.apache.sling.commons.threads.ThreadPool;
-import org.apache.sling.commons.threads.ThreadPoolManager;
import org.apache.sling.scripting.api.CachedScript;
import org.apache.sling.scripting.api.ScriptCache;
import org.apache.sling.scripting.core.impl.helper.CachingMap;
@@ -91,13 +92,11 @@ public class ScriptCacheImpl implements ScriptCache, ResourceChangeListener, Ext
@Reference
private ResourceResolverFactory rrf;
- @Reference
- private ThreadPoolManager threadPoolManager;
@Reference
private SlingScriptEngineManager slingScriptEngineManager;
- private ThreadPool threadPool;
+ private volatile ExecutorService threadPool;
private final ReentrantReadWriteLock rwl = new ReentrantReadWriteLock();
private final Lock readLock = rwl.readLock();
private final Lock writeLock = rwl.writeLock();
@@ -201,7 +200,7 @@ public class ScriptCacheImpl implements ScriptCache, ResourceChangeListener, Ext
@Activate
protected void activate(ScriptCacheImplConfiguration configuration, BundleContext bundleCtx) {
- threadPool = threadPoolManager.get("Script Cache Thread Pool");
+ threadPool = Executors.newSingleThreadExecutor();
bundleContext = bundleCtx;
additionalExtensions = configuration.org_apache_sling_scripting_cache_additional__extensions();
int newMaxCacheSize = configuration.org_apache_sling_scripting_cache_size();
@@ -260,7 +259,12 @@ public class ScriptCacheImpl implements ScriptCache, ResourceChangeListener, Ext
resourceChangeListener = null;
}
if (threadPool != null) {
- threadPoolManager.release(threadPool);
+ threadPool.shutdown();
+ try {
+ threadPool.awaitTermination(1, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ logger.warn("Unable to shutdown script cache thread in time");
+ }
threadPool = null;
}
active = false;