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-6663) Time-consuming operation with lock held in ServerSocketChannelImpl.java
Date Tue, 28 Sep 2010 04:54:34 GMT
Time-consuming operation with lock held in ServerSocketChannelImpl.java 
------------------------------------------------------------------------

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


I found a time-consuming operation with lock held in modules/nio/src/main/java/common/org/apache/harmony/nio/internal/ServerSocketChannelImpl.java

public SocketChannel accept() throws IOException {
      ...
            synchronized (acceptLock) {
                    boolean isBlocking = isBlocking();
                    ...
                    do {
                        try {
                            ((ServerSocketAdapter) socket).accept(socketGot,
                                    (SocketChannelImpl) sockChannel);
                            // select successfully, break out immediately.
                            break;
                        } catch (SocketTimeoutException e) {
                            // continue to accept if the channel is in blocking
                            // mode.
                        }
                    } while (isBlocking);
            }
        ...
    }

Thread A executes accept() method, holds a lock on "acceptLock ", but may block at socket.accept()
for a long time.
Thread B executes accept(), cannot acquire the lock on "acceptLock ".

Consequence:
Lock contends, significantly downgrade software performance.

I suggest to move the do-while block out of the synchronization block as follow:
public SocketChannel accept() throws IOException {
      ...
            boolean isBlocking = isBlocking();
            synchronized (acceptLock) {   
                    ...
             }
               do {
                        try {
                            ((ServerSocketAdapter) socket).accept(socketGot,
                                    (SocketChannelImpl) sockChannel);
                            // select successfully, break out immediately.
                            break;
                        } catch (SocketTimeoutException e) {
                            // continue to accept if the channel is in blocking
                            // mode.
                        }
                    } while (isBlocking);

        ...
    }


-- 
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