Name: rmT116609 Date: 03/05/2002
FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
DESCRIPTION OF THE PROBLEM :
I have a thread acepting network connections in ServerSocketChannel.accept(). When I need to cleanly shutdown my program, I interrupt() the thread which is
blocked in accept(), catch the ClosedByInterruptException and cleanly shutdown.
This worked fine under JDK build 1.4.0-beta3-b84.
Under build 1.4.0-b92, the thread blocked in accept() does not respond to the interrupt(). Under JBuilder 6 debugger, I see the following stack when I pause the program after calling interrupt():
java.lang.Thread interrupt() (Thread.java:741)
java.nio.channels.spi.AbstractInterruptibleChannel$1
interrupt() (AbstractInterruptibleChannel.java:147)
java.nio.channels.spi.AbstractSelectableChannel
implCloseChannel() (AbstractSelectableChannel.java:202)
sun.nio.ch.ServerSocketChannelImpl
implCloseSelectableChannel()
(ServerSocketChannelImpl.java:153)
sun.nio.ch.ServerSocketChannelImpl kill()
(ServerSocketChannelImpl.java:158)
The system just hangs there.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create a thread which blocks in ServerSocketChannel.accept()
2. From another thread, call Thread.interrupt() on the previous thread.
3. The first thread will hang in ServerSocketChannelImpl.kill()
EXPECTED VERSUS ACTUAL BEHAVIOR :
Using the attached test program, I see the folloing output from test runs under the two different JDK's.
-------------------------------------------------------
C:\work\test>java -version
java version "1.4.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build
1.4.0-beta3-b84)
Java HotSpot(TM) Client VM (build 1.4.0-beta3-b84, mixed
mode)
C:\work\test>java dave.shutdowntest
Creating thread...
Starting thread...
Thread running.
Accepting...
Interrupting thread...
Closed By Interrupt!!!
Test done.
C:\work\test>
-------------------------------------------------------
C:\work\test>java -version
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build
1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
C:\work\test>java dave.shutdowntest
Creating thread...
Starting thread...
Thread running.
Accepting...
Interrupting thread...
(program never terminates)
-------------------------------------------------------
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package dave;
import java.io.*;
import java.net.*;
import java.nio.*;
import java.nio.channels.*;
public class shutdowntest
{
class AcceptThread extends Thread
{
public void run()
{
System.out.println("Thread running.");
try
{
ServerSocketChannel channel = ServerSocketChannel.open();
InetSocketAddress address = new InetSocketAddress(InetAddress.getLocalHost(),7000);
channel.socket().bind(address);
while (!isInterrupted())
{
System.out.println("Accepting...");
SocketChannel socketChannel = channel.accept();
System.out.println("Accepted.");
Socket socket = socketChannel.socket();
System.out.println("Accepted connection: " + socket.toString());
socket.close();
}
}
catch(BindException be)
{
System.out.println("BIND address already in use");
}
catch (ClosedByInterruptException cbie)
{
System.out.println("Closed By Interrupt!!!");
}
catch(IOException ioe)
{
System.out.println("IOException: " + ioe);
}
}
}
public shutdowntest()
{
}
public void test() throws Exception
{
System.out.println("Creating thread...");
AcceptThread t = new AcceptThread();
System.out.println("Starting thread...");
t.start();
Thread.currentThread().sleep(10000);
System.out.println("Interrupting thread...");
t.interrupt();
Thread.currentThread().sleep(10000);
System.out.println("Test done.");
}
/**
*
*/
public static void main(String[] args) throws Exception
{
new shutdowntest().test();
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
Stopping the application using Ctrl-C.
Release Regression From : merlin-beta3
The above release value was the last known release where this
bug was knwon to work. Since then there has been a regression.
(Review ID: 143484)
======================================================================