--- old/src/share/classes/java/sql/DriverManager.java 2014-10-30 17:36:56.000000000 -0400
+++ new/src/share/classes/java/sql/DriverManager.java 2014-10-30 17:36:56.000000000 -0400
@@ -88,20 +88,13 @@
private static volatile java.io.PrintStream logStream = null;
// Used in println() to synchronize logWriter
private final static Object logSync = new Object();
+ // Used in initDriversIfNeeded() to synchronize driversInitialized
+ private final static Object driversSync = new Object();
+ private static volatile boolean driversInitialized;
/* Prevent the DriverManager class from being instantiated. */
private DriverManager(){}
-
- /**
- * Load the initial JDBC drivers by checking the System property
- * jdbc.properties and then use the {@code ServiceLoader} mechanism
- */
- static {
- loadInitialDrivers();
- println("JDBC DriverManager initialized");
- }
-
/**
* The SQLPermission
constant that allows the
* setting of the logging stream.
@@ -286,6 +279,8 @@
throws SQLException {
println("DriverManager.getDriver(\"" + url + "\")");
+
+ initDriversIfNeeded();
Class> callerClass = Reflection.getCallerClass();
@@ -328,7 +323,7 @@
* @exception SQLException if a database access error occurs
* @exception NullPointerException if {@code driver} is null
*/
- public static synchronized void registerDriver(java.sql.Driver driver)
+ public static void registerDriver(java.sql.Driver driver)
throws SQLException {
registerDriver(driver, null);
@@ -349,10 +344,10 @@
* @exception NullPointerException if {@code driver} is null
* @since 1.8
*/
- public static synchronized void registerDriver(java.sql.Driver driver,
+ public static void registerDriver(java.sql.Driver driver,
DriverAction da)
throws SQLException {
-
+
/* Register the driver if it has not already been added to our list */
if(driver != null) {
registeredDrivers.addIfAbsent(new DriverInfo(driver, da));
@@ -436,6 +431,8 @@
@CallerSensitive
public static java.util.Enumeration getDrivers() {
java.util.Vector result = new java.util.Vector<>();
+
+ initDriversIfNeeded();
Class> callerClass = Reflection.getCallerClass();
@@ -564,6 +561,26 @@
return result;
}
+ /*
+ * Load the initial JDBC drivers by checking the System property
+ * jdbc.properties and then use the {@code ServiceLoader} mechanism
+ */
+ private static void initDriversIfNeeded() {
+ // Drivers have been inited earleir
+ if (driversInitialized) {
+ return;
+ }
+
+ synchronized(driversSync) {
+ if (driversInitialized) {
+ return;
+ }
+ loadInitialDrivers();
+ driversInitialized = true;
+ println("JDBC DriverManager initialized");
+ }
+ }
+
private static void loadInitialDrivers() {
String drivers;
try {
@@ -650,6 +667,8 @@
}
println("DriverManager.getConnection(\"" + url + "\")");
+
+ initDriversIfNeeded();
// Walk through the loaded registeredDrivers attempting to make a connection.
// Remember the first exception that gets raised so we can reraise it.