Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 85406 invoked from network); 28 Sep 2010 04:54:58 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 28 Sep 2010 04:54:58 -0000 Received: (qmail 3253 invoked by uid 500); 28 Sep 2010 04:54:58 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 3076 invoked by uid 500); 28 Sep 2010 04:54:56 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 3055 invoked by uid 99); 28 Sep 2010 04:54:55 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Sep 2010 04:54:55 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.22] (HELO thor.apache.org) (140.211.11.22) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Sep 2010 04:54:54 +0000 Received: from thor (localhost [127.0.0.1]) by thor.apache.org (8.13.8+Sun/8.13.8) with ESMTP id o8S4sYF8018414 for ; Tue, 28 Sep 2010 04:54:34 GMT Message-ID: <14139549.435751285649674171.JavaMail.jira@thor> Date: Tue, 28 Sep 2010 00:54:34 -0400 (EDT) From: "Wendy Feng (JIRA)" To: commits@harmony.apache.org Subject: [jira] Created: (HARMONY-6663) Time-consuming operation with lock held in ServerSocketChannelImpl.java MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 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.