db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpendle...@apache.org
Subject svn commit: r833888 - /db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedDataSource.java
Date Sun, 08 Nov 2009 15:40:34 GMT
Author: bpendleton
Date: Sun Nov  8 15:40:34 2009
New Revision: 833888

URL: http://svn.apache.org/viewvc?rev=833888&view=rev
Log:
DERBY-4124: Remove double-checked-locking from EmbeddedDataSource.findDriver

This change ensures that EmbeddedDataSource.findDriver always synchronizes
its access to the 'driver' member variable. The previous code performed
unsynchronized access to the field, and then, depending on the results of
the unsynchronized access, performed synchronized access.

This double-checked-locking idiom is unsafe and incorrect, and this change
replaces it with a simpler always-synchronized access.


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedDataSource.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedDataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedDataSource.java?rev=833888&r1=833887&r2=833888&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedDataSource.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbeddedDataSource.java Sun Nov
 8 15:40:34 2009
@@ -490,25 +490,22 @@
 	{
 		String url = jdbcurl;
 
-		if (driver == null || !driver.acceptsURL(url))
+		synchronized(this)
 		{
-			synchronized(this)
+			// The driver has either never been booted, or it has been
+			// shutdown by a 'jdbc:derby:;shutdown=true'
+			if (driver == null || !driver.acceptsURL(url))
 			{
-				// The driver has either never been booted, or it has been
-				// shutdown by a 'jdbc:derby:;shutdown=true'
-				if (driver == null || !driver.acceptsURL(url))
-				{
-
-					new org.apache.derby.jdbc.EmbeddedDriver();
-
-					// If we know the driver, we loaded it.   Otherwise only
-					// work if DriverManager has already loaded it.
-
-					AutoloadedDriver	autoloadedDriver =
-						(AutoloadedDriver) DriverManager.getDriver(url);
-					driver = (InternalDriver) autoloadedDriver.getDriverModule();
-					// DriverManager will throw an exception if it cannot find the driver
-				}
+
+				new org.apache.derby.jdbc.EmbeddedDriver();
+
+				// If we know the driver, we loaded it.   Otherwise only
+				// work if DriverManager has already loaded it.
+
+				AutoloadedDriver	autoloadedDriver =
+					(AutoloadedDriver) DriverManager.getDriver(url);
+				driver = (InternalDriver) autoloadedDriver.getDriverModule();
+				// DriverManager will throw an exception if it cannot find the driver
 			}
 		}
 		return driver;



Mime
View raw message