From 882de20e1cd077859d88a0eebc8dbf3717afb100 Mon Sep 17 00:00:00 2001 From: Daan Hoogland Date: Fri, 14 Aug 2015 16:03:17 +0200 Subject: [PATCH] CLOUDSTACK-8656: reorganise sychronized block --- .../cloud/utils/db/ConnectionConcierge.java | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/framework/db/src/com/cloud/utils/db/ConnectionConcierge.java b/framework/db/src/com/cloud/utils/db/ConnectionConcierge.java index f5a3b2f0f17..a1c473d5ffd 100644 --- a/framework/db/src/com/cloud/utils/db/ConnectionConcierge.java +++ b/framework/db/src/com/cloud/utils/db/ConnectionConcierge.java @@ -142,26 +142,17 @@ public class ConnectionConcierge { } protected String testValidity(String name, Connection conn) { - PreparedStatement pstmt = null; - try { - if (conn != null) { - synchronized (conn) { - pstmt = conn.prepareStatement("SELECT 1"); + if (conn != null) { + synchronized (conn) { + try (PreparedStatement pstmt = conn.prepareStatement("SELECT 1");) { pstmt.executeQuery(); - } - } - return null; - } catch (Throwable th) { - s_logger.error("Unable to keep the db connection for " + name, th); - return th.toString(); - } finally { - if (pstmt != null) { - try { - pstmt.close(); - } catch (SQLException e) { + } catch (Throwable th) { + s_logger.error("Unable to keep the db connection for " + name, th); + return th.toString(); } } } + return null; } @Override