Torque
  1. Torque
  2. TORQUE-124

Thread safety problem in JndiDataSourceFactory

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 3.3
    • Fix Version/s: 4.0-beta1
    • Component/s: Runtime
    • Labels:
      None

      Description

      javax.naming.InitialContext is not thread safe.
      http://java.sun.com/j2se/1.5.0/docs/api/javax/naming/InitialContext.html
      Threads that need to access a single InitialContext instance concurrently should synchronize
      amongst themselves and provide the necessary locking.

      In JndiDataSourceFactory#getDataSource, InitialContext #lookup is called without synchronization.
      This can be potential thread safe problems under the high load systems.

      public DataSource getDataSource() throws TorqueException
      {
      long time = System.currentTimeMillis();

      if (ds == null || time - lastLookup > ttl)
      {
      try

      { ds = ((DataSource) ctx.lookup(path)); lastLookup = time; }

      catch (Exception e)

      { throw new TorqueException(e); }

      }

      return ds;
      }

        Activity

        Kazu Nambo created issue -
        Hide
        Thomas Fox added a comment -

        Fixed by synchronizing the access to the context

        Show
        Thomas Fox added a comment - Fixed by synchronizing the access to the context
        Thomas Fox made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Assignee Thomas Fox [ tfischer ]
        Fix Version/s 4.0 [ 12312102 ]
        Resolution Fixed [ 1 ]
        Thomas Fox made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

          • Assignee:
            Thomas Fox
            Reporter:
            Kazu Nambo
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development