You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2015/06/19 17:14:16 UTC

[1/2] activemq git commit: https://issues.apache.org/jira/browse/AMQ-5811

Repository: activemq
Updated Branches:
  refs/heads/master f2a335c27 -> a35be76ff


https://issues.apache.org/jira/browse/AMQ-5811

Added synchronization blocks around sentitive code to
prevent concurrent modification of the HashMap.


Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/a1062c27
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/a1062c27
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/a1062c27

Branch: refs/heads/master
Commit: a1062c273f8c02b6b6311397d2c0e4059054a1a8
Parents: f2a335c
Author: Howard Gao <hg...@redhat.com>
Authored: Fri Jun 12 13:41:05 2015 +0800
Committer: Timothy Bish <ta...@gmail.com>
Committed: Fri Jun 19 11:13:08 2015 -0400

----------------------------------------------------------------------
 .../activemq/ra/ActiveMQResourceAdapter.java    | 14 ++--
 .../java/org/apache/activemq/ra/MDBTest.java    | 72 ++++++++++++++++++++
 2 files changed, 81 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/a1062c27/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQResourceAdapter.java
----------------------------------------------------------------------
diff --git a/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQResourceAdapter.java b/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQResourceAdapter.java
index 9ae948a..8c5d4ca 100644
--- a/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQResourceAdapter.java
+++ b/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQResourceAdapter.java
@@ -147,9 +147,11 @@ public class ActiveMQResourceAdapter extends ActiveMQConnectionSupport implement
      * @see javax.resource.spi.ResourceAdapter#stop()
      */
     public void stop() {
-        while (endpointWorkers.size() > 0) {
-            ActiveMQEndpointActivationKey key = endpointWorkers.keySet().iterator().next();
-            endpointDeactivation(key.getMessageEndpointFactory(), key.getActivationSpec());
+        synchronized (endpointWorkers) {
+            while (endpointWorkers.size() > 0) {
+                ActiveMQEndpointActivationKey key = endpointWorkers.keySet().iterator().next();
+                endpointDeactivation(key.getMessageEndpointFactory(), key.getActivationSpec());
+            }
         }
         
         synchronized( this ) {
@@ -205,10 +207,12 @@ public class ActiveMQResourceAdapter extends ActiveMQConnectionSupport implement
      *      javax.resource.spi.ActivationSpec)
      */
     public void endpointDeactivation(MessageEndpointFactory endpointFactory, ActivationSpec activationSpec) {
-
         if (activationSpec instanceof MessageActivationSpec) {
             ActiveMQEndpointActivationKey key = new ActiveMQEndpointActivationKey(endpointFactory, (MessageActivationSpec)activationSpec);
-            ActiveMQEndpointWorker worker = endpointWorkers.remove(key);
+            ActiveMQEndpointWorker worker = null;
+            synchronized (endpointWorkers) {
+                worker = endpointWorkers.remove(key);
+            }
             if (worker == null) {
                 // This is weird.. that endpoint was not activated.. oh well..
                 // this method

http://git-wip-us.apache.org/repos/asf/activemq/blob/a1062c27/activemq-ra/src/test/java/org/apache/activemq/ra/MDBTest.java
----------------------------------------------------------------------
diff --git a/activemq-ra/src/test/java/org/apache/activemq/ra/MDBTest.java b/activemq-ra/src/test/java/org/apache/activemq/ra/MDBTest.java
index af36389..89c80c0 100644
--- a/activemq-ra/src/test/java/org/apache/activemq/ra/MDBTest.java
+++ b/activemq-ra/src/test/java/org/apache/activemq/ra/MDBTest.java
@@ -274,6 +274,78 @@ public class MDBTest extends TestCase {
 
     }
 
+    //https://issues.apache.org/jira/browse/AMQ-5811
+    public void testAsyncStop() throws Exception {
+        for (int repeat = 0; repeat < 10; repeat++) {
+            ActiveMQResourceAdapter adapter = new ActiveMQResourceAdapter();
+            adapter.setServerUrl("vm://localhost?broker.persistent=false");
+            adapter.setQueuePrefetch(1);
+            adapter.start(new StubBootstrapContext());
+
+            final int num = 20;
+            MessageEndpointFactory[] endpointFactories = new MessageEndpointFactory[num];
+            ActiveMQActivationSpec[] activationSpecs = new ActiveMQActivationSpec[num];
+
+            for (int i = 0; i < num; i++) {
+
+                final StubMessageEndpoint endpoint = new StubMessageEndpoint()
+                {
+                    public void onMessage(Message message)
+                    {
+                        super.onMessage(message);
+                    }
+                };
+
+                activationSpecs[i] = new ActiveMQActivationSpec();
+                activationSpecs[i].setDestinationType(Queue.class.getName());
+                activationSpecs[i].setDestination("TEST" + i);
+                activationSpecs[i].setResourceAdapter(adapter);
+                activationSpecs[i].validate();
+
+                endpointFactories[i] = new MessageEndpointFactory() {
+                    public MessageEndpoint createEndpoint(XAResource resource) throws UnavailableException {
+                        endpoint.xaresource = resource;
+                        return endpoint;
+                    }
+
+                    public boolean isDeliveryTransacted(Method method) throws NoSuchMethodException {
+                        return true;
+                    }
+                };
+
+                // Activate an Endpoint
+                adapter.endpointActivation(endpointFactories[i], activationSpecs[i]);
+            }
+
+            //spawn num threads to deactivate
+            Thread[] threads = asyncDeactivate(adapter, endpointFactories, activationSpecs);
+            for (int i = 0; i < threads.length; i++) {
+                threads[i].start();
+            }
+            adapter.stop();
+            for (int i = 0; i < threads.length; i++) {
+                threads[i].join();
+            }
+        }
+    }
+
+    private Thread[] asyncDeactivate(final ActiveMQResourceAdapter adapter,
+                                     final MessageEndpointFactory[] endpointFactories,
+                                     final ActiveMQActivationSpec[] activationSpecs) {
+        Thread[] threads = new Thread[endpointFactories.length];
+        for (int i = 0; i < threads.length; i++) {
+            final MessageEndpointFactory endpointFactory = endpointFactories[i];
+            final ActiveMQActivationSpec activationSpec = activationSpecs[i];
+
+            threads[i] = new Thread() {
+                public void run() {
+                    adapter.endpointDeactivation(endpointFactory, activationSpec);
+                }
+            };
+        }
+        return threads;
+    }
+
     public void testErrorOnNoMessageDeliveryBrokerZeroPrefetchConfig() throws Exception {
 
         final BrokerService brokerService = new BrokerService();


[2/2] activemq git commit: This closes #112

Posted by ta...@apache.org.
This closes #112


Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/a35be76f
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/a35be76f
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/a35be76f

Branch: refs/heads/master
Commit: a35be76ff3dfb5882f2e2d2696534879f8a9ebf0
Parents: f2a335c a1062c2
Author: Timothy Bish <ta...@gmail.com>
Authored: Fri Jun 19 11:13:55 2015 -0400
Committer: Timothy Bish <ta...@gmail.com>
Committed: Fri Jun 19 11:13:55 2015 -0400

----------------------------------------------------------------------
 .../activemq/ra/ActiveMQResourceAdapter.java    | 14 ++--
 .../java/org/apache/activemq/ra/MDBTest.java    | 72 ++++++++++++++++++++
 2 files changed, 81 insertions(+), 5 deletions(-)
----------------------------------------------------------------------