Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Won't Fix
-
6.0M1
-
None
-
None
-
Windows XP
Description
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
} 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);
...
}