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 2012/10/03 17:45:38 UTC
svn commit: r1393561 -
/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/core/ActiveMQConnection.cpp
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();