Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4912686

DriverManager.getConnection should not be synchronized

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.0
    • core-libs
    • x86
    • windows_2000

      Name: gm110360 Date: 08/26/2003


      FULL PRODUCT VERSION :
      java version "1.4.1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
      Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)

      FULL OPERATING SYSTEM VERSION :
      Microsoft Windows 2000 [Version 5.00.2195]


      A DESCRIPTION OF THE PROBLEM :
      Do not close this bug as a duplicate unless you have read
      further.

      DriverManager.getConnection() should not be synchronized.
      The javadoc says that is should not be synchronized. The
      engineer who closed 4263113 contended that a lot of
      jdbc-enabled applications have come to expect the
      synchronized behavior. My contention is how could they? The
      javadoc clearly says:
      "public static Connection getConnection(String url,
                                     String user, String password)
      throws SQLException"

      "Not public static synchronized Connection ......"

      Anyone who did clearly could not understand the java
      documentation.

      Also the workaround to use DataSource.getConnection instead
      since it is not synchronized also isn't valid and does not
      take in to account that fact that DataSouce.getConnection is
      most likely going to call DriverManager.getConnection since
      they both return an object implementing the same interface.

      for example the "thin" jdbc driver shipping with Oracle
      8.1.7 has an implementation of DataSource called
      OracleDataSource. It used a decompiler on it to get the
      source code. Here is the source for the getConnection method



          public synchronized Connection getConnection(String
      string1, String string2)

              throws SQLException

          {

              makeURL();

              trace(string1 + "URL is " + m_url);

              Connection connection = null;

              if (m_use_defConn)

              {

                  if (m_od == null)

                      m_od = new OracleDriver();

                  connection = m_od.defaultConnection();

              }

              else

                  connection = DriverManager.getConnection(m_url,
      string1, string2);

              return connection;

          }

      The fact that OracleDataSource.getConnection itself is
      synchronized is unrelated and not significant since it is
      not static and one has to create a separate OracleDataSource
      instance for every database.

      The problem is that OracleDataSource calls
      DriverManager.getConnection(), which is a static
      synchronized method. Therefore a hung jdbc connection
      attempt for one Oracle database locks up all subsequent jdbc
      connection attempts for the life cycle of the jvm.

      Oracle cannot be faulted for implementing getConnection the
      way they did since they followed the contract specified by
      the javadoc that DriverManager.getConnection() is not
      synchronized; another example of the expectations of the
      behavior of DriverManager.getConnection.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      CUSTOMER WORKAROUND :
      Modify DriverManager so that getConnection is not synchronized.
      (Incident Review ID: 165686)
      ======================================================================

            ahandasunw Amit Handa (Inactive)
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: