Go ahead and implement double-checked locking, this is a low traffic method.

pull/201/head
Brett Wooldridge 11 years ago
parent d71db82715
commit ad3f9eaa55

@ -233,22 +233,29 @@ public final class PoolUtilities
*/ */
public static boolean isJdbc40Compliant(final Connection connection) throws SQLException public static boolean isJdbc40Compliant(final Connection connection) throws SQLException
{ {
if (!jdbc40checked) { // See http://en.wikipedia.org/wiki/Double-checked_locking#Usage_in_Java
try { boolean checked = jdbc40checked;
connection.isValid(5); // This will throw AbstractMethodError or SQLException in the case of a non-JDBC 41 compliant driver if (!checked) {
IS_JDBC40 = true; synchronized (PoolUtilities.class) {
} checked = jdbc40checked;
catch (SQLFeatureNotSupportedException e) { if (!checked) {
IS_JDBC40 = false; try {
} connection.isValid(5); // This will throw AbstractMethodError or SQLException in the case of a non-JDBC 41 compliant driver
catch (AbstractMethodError e) { IS_JDBC40 = true;
IS_JDBC40 = false; }
} catch (SQLFeatureNotSupportedException e) {
catch (NoSuchMethodError e) { IS_JDBC40 = false;
IS_JDBC40 = false; }
} catch (AbstractMethodError e) {
finally { IS_JDBC40 = false;
jdbc40checked = true; }
catch (NoSuchMethodError e) {
IS_JDBC40 = false;
}
finally {
jdbc40checked = checked = true;
}
}
} }
} }

@ -215,16 +215,23 @@ public final class PoolUtilities
*/ */
public static boolean isJdbc40Compliant(final Connection connection) throws SQLException public static boolean isJdbc40Compliant(final Connection connection) throws SQLException
{ {
if (!jdbc40checked) { // See http://en.wikipedia.org/wiki/Double-checked_locking#Usage_in_Java
try { boolean checked = jdbc40checked;
connection.isValid(5); // This will throw AbstractMethodError or SQLException in the case of a non-JDBC 41 compliant driver if (!checked) {
IS_JDBC40 = true; synchronized (PoolUtilities.class) {
} checked = jdbc40checked;
catch (NoSuchMethodError | AbstractMethodError | SQLFeatureNotSupportedException e) { if (!checked) {
IS_JDBC40 = false; try {
} connection.isValid(5); // This will throw AbstractMethodError or SQLException in the case of a non-JDBC 41 compliant driver
finally { IS_JDBC40 = true;
jdbc40checked = true; }
catch (NoSuchMethodError | AbstractMethodError | SQLFeatureNotSupportedException e) {
IS_JDBC40 = false;
}
finally {
jdbc40checked = checked = true;
}
}
} }
} }

Loading…
Cancel
Save