activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1393561 - /activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp
Date Wed, 03 Oct 2012 15:45:38 GMT
Author: tabish
Date: Wed Oct  3 15:45:38 2012
New Revision: 1393561

URL: http://svn.apache.org/viewvc?rev=1393561&view=rev
Log:
Ensure the ExecutorService is terminated in the destructor to avoid segfault.  
Make sure to use copies of list elements that can otherwise lead to ConcurrentModificationException.

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp?rev=1393561&r1=1393560&r2=1393561&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp
Wed Oct  3 15:45:38 2012
@@ -253,6 +253,15 @@ namespace core{
             this->scheduler->start();
         }
 
+        ~ConnectionConfig() {
+            try {
+                this->scheduler->shutdown();
+                this->executor->shutdown();
+                this->executor->awaitTermination(1, TimeUnit::MINUTES);
+            }
+            AMQ_CATCHALL_NOTHROW()
+        }
+
         void waitForBrokerInfo() {
             this->brokerInfoReceived->await();
         }
@@ -687,8 +696,9 @@ void ActiveMQConnection::cleanup() {
 
         this->config->sessionsLock.writeLock().lock();
         try {
-            // Get the complete list of active sessions.
-            std::auto_ptr< Iterator< Pointer<ActiveMQSessionKernel> > >
iter( this->config->activeSessions.iterator() );
+            // We need to use a copy since we aren't able to use CopyOnWriteArrayList
+            ArrayList<Pointer<ActiveMQSessionKernel> > sessions(this->config->activeSessions);
+            std::auto_ptr< Iterator< Pointer<ActiveMQSessionKernel> > >
iter(sessions.iterator());
 
             // Dispose of all the Session resources we know are still open.
             while (iter->hasNext()) {
@@ -699,6 +709,7 @@ void ActiveMQConnection::cleanup() {
                     /* Absorb */
                 }
             }
+            this->config->activeSessions.clear();
             this->config->sessionsLock.writeLock().unlock();
         } catch (Exception& ex) {
             this->config->sessionsLock.writeLock().unlock();



Mime
View raw message