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

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

@ -233,22 +233,29 @@ public final class PoolUtilities
*/
public static boolean isJdbc40Compliant(final Connection connection) throws SQLException
{
if (!jdbc40checked) {
try {
connection.isValid(5); // This will throw AbstractMethodError or SQLException in the case of a non-JDBC 41 compliant driver
IS_JDBC40 = true;
}
catch (SQLFeatureNotSupportedException e) {
IS_JDBC40 = false;
}
catch (AbstractMethodError e) {
IS_JDBC40 = false;
}
catch (NoSuchMethodError e) {
IS_JDBC40 = false;
}
finally {
jdbc40checked = true;
// 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 {
connection.isValid(5); // This will throw AbstractMethodError or SQLException in the case of a non-JDBC 41 compliant driver
IS_JDBC40 = true;
}
catch (SQLFeatureNotSupportedException e) {
IS_JDBC40 = false;
}
catch (AbstractMethodError e) {
IS_JDBC40 = false;
}
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
{
if (!jdbc40checked) {
try {
connection.isValid(5); // This will throw AbstractMethodError or SQLException in the case of a non-JDBC 41 compliant driver
IS_JDBC40 = true;
}
catch (NoSuchMethodError | AbstractMethodError | SQLFeatureNotSupportedException e) {
IS_JDBC40 = false;
}
finally {
jdbc40checked = true;
// 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 {
connection.isValid(5); // This will throw AbstractMethodError or SQLException in the case of a non-JDBC 41 compliant driver
IS_JDBC40 = true;
}
catch (NoSuchMethodError | AbstractMethodError | SQLFeatureNotSupportedException e) {
IS_JDBC40 = false;
}
finally {
jdbc40checked = checked = true;
}
}
}
}

Loading…
Cancel
Save