Author: epbernard
Date: 2008-08-05 19:47:13 -0400 (Tue, 05 Aug 2008)
New Revision: 15018
Modified:
search/trunk/src/java/org/hibernate/search/backend/impl/jms/JMSBackendQueueProcessor.java
Log:
Avoid JMS connection leak
Modified:
search/trunk/src/java/org/hibernate/search/backend/impl/jms/JMSBackendQueueProcessor.java
===================================================================
---
search/trunk/src/java/org/hibernate/search/backend/impl/jms/JMSBackendQueueProcessor.java 2008-08-05
16:31:07 UTC (rev 15017)
+++
search/trunk/src/java/org/hibernate/search/backend/impl/jms/JMSBackendQueueProcessor.java 2008-08-05
23:47:13 UTC (rev 15018)
@@ -10,6 +10,9 @@
import javax.jms.QueueSender;
import javax.jms.QueueSession;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import org.hibernate.HibernateException;
import org.hibernate.search.backend.LuceneWork;
import org.hibernate.search.backend.OptimizeLuceneWork;
@@ -20,6 +23,7 @@
public class JMSBackendQueueProcessor implements Runnable {
private List<LuceneWork> queue;
private JMSBackendQueueProcessorFactory factory;
+ private Logger log = LoggerFactory.getLogger( JMSBackendQueueProcessor.class );
public JMSBackendQueueProcessor(List<LuceneWork> queue,
JMSBackendQueueProcessorFactory jmsBackendQueueProcessorFactory) {
@@ -37,7 +41,7 @@
}
if ( filteredQueue.size() == 0) return;
factory.prepareJMSTools();
- QueueConnection cnn;
+ QueueConnection cnn = null;
QueueSender sender;
QueueSession session;
try {
@@ -52,10 +56,18 @@
sender.send( message );
session.close();
- cnn.close();
}
catch (JMSException e) {
throw new HibernateException( "Unable to send Search work to JMS queue: " +
factory.getJmsQueueName(), e );
}
+ finally {
+ try {
+ if (cnn != null)
+ cnn.close();
+ }
+ catch ( JMSException e ) {
+ log.warn( "Unable to close JMS connection for " +
factory.getJmsQueueName(), e );
+ }
+ }
}
}
Show replies by date