Uploaded image for project: 'Harmony'
  1. Harmony
  2. HARMONY-6662

Spin wait in StartTlsResponseImpl.java

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 6.0M1
    • 5.0M16
    • Classlib
    • None
    • Windows XP

    Description

      I found spin wait in modules/jndi/src/main/java/org/apache/harmony/jndi/provider/ldap/ext/StartTlsResponseImpl.java

      public class StartTlsResponseImpl extends StartTlsResponse {
      ...
      public SSLSession negotiate(SSLSocketFactory factory) throws IOException {
      ...
      sslSocket.startHandshake();

      while (!isHandshaked)

      { // Wait for handshake finish. }

      ...
      }
      ...
      }

      Spin wait for isHandshaked is updated by other threads.

      Consequence:
      Bad performance due to exhaustive use of CPU time.
      In current Java memory model, even if the isHandshaked field is updated by other threads, current thread that spins checking for isHandshaked may not see the up-to-date value, turn the code into an infinite loop.

      I suggest to use wait/notify for synchronization as follow
      public class StartTlsResponseImpl extends StartTlsResponse {
      private static final Object monitor = new Object():
      ...
      public SSLSession negotiate(SSLSocketFactory factory) throws IOException {
      ...
      sslSocket.startHandshake();

      synchronized(monitor){
      while (!isHandshaked)

      { monitor.wait(); }

      }
      ...
      }
      ...
      }

      Pls make sure to change the code that will update the value of isHandshaked correspondingly.

      Attachments

        Activity

          People

            regis_xu Regis Xu
            cashcrop Wendy Feng
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 7h
                7h
                Remaining:
                Remaining Estimate - 7h
                7h
                Logged:
                Time Spent - Not Specified
                Not Specified