activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject svn commit: r734256 - /activemq/trunk/activemq-core/src/main/java/org/apache/activemq/usage/Usage.java
Date Tue, 13 Jan 2009 22:15:27 GMT
Author: gtully
Date: Tue Jan 13 14:15:25 2009
New Revision: 734256

URL: http://svn.apache.org/viewvc?rev=734256&view=rev
Log:
apply patch from https://issues.apache.org/activemq/browse/AMQ-2054

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/usage/Usage.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/usage/Usage.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/usage/Usage.java?rev=734256&r1=734255&r2=734256&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/usage/Usage.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/usage/Usage.java Tue Jan
13 14:15:25 2009
@@ -55,7 +55,7 @@
     private List<T> children = new CopyOnWriteArrayList<T>();
     private final List<Runnable> callbacks = new LinkedList<Runnable>();
     private int pollingTime = 100;
-    private ThreadPoolExecutor executor;
+    private volatile ThreadPoolExecutor executor;
     private AtomicBoolean started=new AtomicBoolean();
 
     public Usage(T parent, String name, float portion) {
@@ -281,7 +281,7 @@
     }
 
     @SuppressWarnings("unchecked")
-    public synchronized void start() {
+    public void start() {
         if (started.compareAndSet(false, true)){
             if (parent != null) {
                 parent.addChild(this);
@@ -293,7 +293,7 @@
     }
 
     @SuppressWarnings("unchecked")
-    public synchronized void stop() {
+    public void stop() {
         if (started.compareAndSet(true, false)){
             if (parent != null) {
                 parent.removeChild(this);
@@ -400,19 +400,22 @@
         this.parent = parent;
     }
     
-    protected synchronized Executor getExecutor() {
+    protected Executor getExecutor() {
         if (this.executor == null) {
-            this.executor = new ThreadPoolExecutor(1, 1, 0,
-                    TimeUnit.NANOSECONDS,
-                    new LinkedBlockingQueue<Runnable>(), new ThreadFactory() {
-                        public Thread newThread(Runnable runnable) {
-                            Thread thread = new Thread(runnable, getName()
-                                    + " Usage Thread Pool");
-                            thread.setDaemon(true);
-                            return thread;
-                        }
-                    });
-
+        	synchronized(usageMutex) {
+        		if (this.executor == null) {
+		            this.executor = new ThreadPoolExecutor(1, 1, 0,
+		                    TimeUnit.NANOSECONDS,
+		                    new LinkedBlockingQueue<Runnable>(), new ThreadFactory() {
+		                        public Thread newThread(Runnable runnable) {
+		                            Thread thread = new Thread(runnable, getName()
+		                                    + " Usage Thread Pool");
+		                            thread.setDaemon(true);
+		                            return thread;
+		                        }
+		                    });
+        		}
+        	}
         }
         return this.executor;
     }



Mime
View raw message