harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Wendy Feng (JIRA)" <j...@apache.org>
Subject [jira] Created: (HARMONY-6662) Spin wait in StartTlsResponseImpl.java
Date Tue, 28 Sep 2010 03:32:50 GMT
Spin wait in StartTlsResponseImpl.java
--------------------------------------

                 Key: HARMONY-6662
                 URL: https://issues.apache.org/jira/browse/HARMONY-6662
             Project: Harmony
          Issue Type: Bug
          Components: Classlib
    Affects Versions: 6.0M1
         Environment: Windows XP
            Reporter: Wendy Feng


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.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message