CLOUDSTACK-8656: reorganise sychronized block

This commit is contained in:
Daan Hoogland 2015-08-14 16:03:17 +02:00
parent 07bee3149c
commit 882de20e1c
1 changed files with 7 additions and 16 deletions

View File

@ -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