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

pull/201/head
Brett Wooldridge
parent d71db82715
commit ad3f9eaa55

@ -233,7 +233,12 @@ 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
boolean checked = jdbc40checked;
if (!checked) {
synchronized (PoolUtilities.class) {
checked = jdbc40checked;
if (!checked) {
try { try {
connection.isValid(5); // This will throw AbstractMethodError or SQLException in the case of a non-JDBC 41 compliant driver connection.isValid(5); // This will throw AbstractMethodError or SQLException in the case of a non-JDBC 41 compliant driver
IS_JDBC40 = true; IS_JDBC40 = true;
@ -248,7 +253,9 @@ public final class PoolUtilities
IS_JDBC40 = false; IS_JDBC40 = false;
} }
finally { finally {
jdbc40checked = true; jdbc40checked = checked = true;
}
}
} }
} }

@ -215,7 +215,12 @@ 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
boolean checked = jdbc40checked;
if (!checked) {
synchronized (PoolUtilities.class) {
checked = jdbc40checked;
if (!checked) {
try { try {
connection.isValid(5); // This will throw AbstractMethodError or SQLException in the case of a non-JDBC 41 compliant driver connection.isValid(5); // This will throw AbstractMethodError or SQLException in the case of a non-JDBC 41 compliant driver
IS_JDBC40 = true; IS_JDBC40 = true;
@ -224,7 +229,9 @@ public final class PoolUtilities
IS_JDBC40 = false; IS_JDBC40 = false;
} }
finally { finally {
jdbc40checked = true; jdbc40checked = checked = true;
}
}
} }
} }

Loading…
Cancel
Save