This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.commons.threads-3.2.0 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-threads.git
commit b2e73eae7543182f126dac7789a09ee0165955cf Author: Ian Boston <[email protected]> AuthorDate: Wed Oct 31 10:49:32 2012 +0000 SLING-2535 wrapped the reference counter in a dedicated synchronised block to ensure that all access to the counter is safe. I think this will be safer than calling from within synchronised blocks as it doesnt rely on the caller remembering the methods need to be single threaded. git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/commons/threads@1404087 13f79535-47bb-0310-9956-ffa450edef68 --- .../threads/impl/DefaultThreadPoolManager.java | 24 +++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/apache/sling/commons/threads/impl/DefaultThreadPoolManager.java b/src/main/java/org/apache/sling/commons/threads/impl/DefaultThreadPoolManager.java index 331d668..65f3059 100644 --- a/src/main/java/org/apache/sling/commons/threads/impl/DefaultThreadPoolManager.java +++ b/src/main/java/org/apache/sling/commons/threads/impl/DefaultThreadPoolManager.java @@ -318,6 +318,12 @@ public class DefaultThreadPoolManager private BundleContext bundleContext; + /** + * This lock protects the counter which is volatile so must be + * protected. + */ + private Object usagelock = new Object(); + public Entry(final String pid, final ThreadPoolConfig config, final String name, final BundleContext bundleContext) { this.pid = pid; this.config = config; @@ -337,17 +343,21 @@ public class DefaultThreadPoolManager } public ThreadPoolFacade incUsage() { - if ( pool == null ) { - pool = new ThreadPoolFacade(new DefaultThreadPool(name, this.config)); + synchronized (usagelock) { + if ( pool == null ) { + pool = new ThreadPoolFacade(new DefaultThreadPool(name, this.config)); + } + this.count++; + return pool; } - this.count++; - return pool; } public void decUsage() { - this.count--; - if ( this.count == 0 ) { - this.shutdown(); + synchronized (usagelock) { + this.count--; + if ( this.count == 0 ) { + this.shutdown(); + } } } -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
