activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rajdav...@apache.org
Subject svn commit: r652302 - /activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/DefaultDatabaseLocker.java
Date Wed, 30 Apr 2008 06:48:20 GMT
Author: rajdavies
Date: Tue Apr 29 23:48:20 2008
New Revision: 652302

URL: http://svn.apache.org/viewvc?rev=652302&view=rev
Log:
Fix for https://issues.apache.org/activemq/browse/AMQ-1702

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/DefaultDatabaseLocker.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/DefaultDatabaseLocker.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/DefaultDatabaseLocker.java?rev=652302&r1=652301&r2=652302&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/DefaultDatabaseLocker.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/store/jdbc/DefaultDatabaseLocker.java
Tue Apr 29 23:48:20 2008
@@ -37,7 +37,6 @@
     private final Statements statements;
     private long sleepTime = 1000;
     private Connection connection;
-    private PreparedStatement statement;
     private boolean stopping;
 
     public DefaultDatabaseLocker(DataSource dataSource, Statements statements) {
@@ -49,7 +48,7 @@
         stopping = false;
 
         LOG.info("Attempting to acquire the exclusive lock to become the Master broker");
-
+        PreparedStatement statement = null;
         while (true) {
             try {
                 connection = dataSource.getConnection();
@@ -97,16 +96,26 @@
     }
 
     public boolean keepAlive() {
+        PreparedStatement statement = null;
+        boolean result = false;
         try {
-            PreparedStatement statement = connection.prepareStatement(statements.getLockUpdateStatement());
+            statement = connection.prepareStatement(statements.getLockUpdateStatement());
             statement.setLong(1, System.currentTimeMillis());
             int rows = statement.executeUpdate();
             if (rows == 1) {
-                return true;
+                result=true;
             }
         } catch (Exception e) {
             LOG.error("Failed to update database lock: " + e, e);
+        }finally {
+            if (statement != null) {
+                try {
+                    statement.close();
+                } catch (SQLException e) {
+                    LOG.error("Failed to close statement",e);
+                }
+            }
         }
-        return false;
+        return result;
     }
 }



Mime
View raw message