Skip to content

Commit 882de20

Browse files
committed
CLOUDSTACK-8656: reorganise sychronized block
1 parent 07bee31 commit 882de20

1 file changed

Lines changed: 7 additions & 16 deletions

File tree

‎framework/db/src/com/cloud/utils/db/ConnectionConcierge.java‎

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -142,26 +142,17 @@ public void unregister(String name) {
142142
}
143143

144144
protected String testValidity(String name, Connection conn) {
145-
PreparedStatement pstmt = null;
146-
try {
147-
if (conn != null) {
148-
synchronized (conn) {
149-
pstmt = conn.prepareStatement("SELECT 1");
145+
if (conn != null) {
146+
synchronized (conn) {
147+
try (PreparedStatement pstmt = conn.prepareStatement("SELECT 1");) {
150148
pstmt.executeQuery();
151-
}
152-
}
153-
return null;
154-
} catch (Throwable th) {
155-
s_logger.error("Unable to keep the db connection for " + name, th);
156-
return th.toString();
157-
} finally {
158-
if (pstmt != null) {
159-
try {
160-
pstmt.close();
161-
} catch (SQLException e) {
149+
} catch (Throwable th) {
150+
s_logger.error("Unable to keep the db connection for " + name, th);
151+
return th.toString();
162152
}
163153
}
164154
}
155+
return null;
165156
}
166157

167158
@Override

0 commit comments

Comments
 (0)