i386/159787: openjdk 1.6 nio muti-thread bug
arli weng
url at 163.com
Mon Aug 15 10:30:10 UTC 2011
>Number: 159787
>Category: i386
>Synopsis: openjdk 1.6 nio muti-thread bug
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-i386
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Mon Aug 15 10:30:09 UTC 2011
>Closed-Date:
>Last-Modified:
>Originator: arli weng
>Release: 8.2
>Organization:
>Environment:
~>uname -a
FreeBSD absd-nb.f13 8.2-RELEASE FreeBSD 8.2-RELEASE #0: Sat Feb 26 20:46:49 CST 2011 root at absd-nb.f13:/usr/obj/usr/src/sys/ARLI_F8SV i386
~>java -version
openjdk version "1.6.0"
OpenJDK Runtime Environment (build 1.6.0-b23)
OpenJDK Client VM (build 20.0-b11, mixed mode)
~>pkg_info |grep openjdk
openjdk6-b23_1 Oracle's Java 6 virtual machine release under the GPL v2
>Description:
on freebsd, java's nio has muti-thread bug, work fine at linux version openjdk.
>How-To-Repeat:
1, create and run the code(see below)
2, run command: nc localhost 9999
3, send anything via nc (input a char and enter key)
4, you can see the connect its close
5, run command again: nc localhost 9999
6, send anything via nc (input a char and enter key)
7, dead here... but openjdk on linux its work fine (disconnect again)
the java source code:
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.Iterator;
import java.util.Set;
public class Test2 {
public static void main(final String[] args) throws Exception {
final ServerSocketChannel sChannel = ServerSocketChannel.open();
sChannel.configureBlocking(false);
final ServerSocket sSock = sChannel.socket();
sSock.bind(new InetSocketAddress(9999), 10);
final SelectionKey acpKey = sChannel.register(Selector.open(),
SelectionKey.OP_ACCEPT);
final ByteBuffer buff = ByteBuffer.allocate(8192);
for (;;) {
if (acpKey.selector().select() == 0) continue;
final Set<SelectionKey> rdyKey = acpKey.selector().selectedKeys();
for (final Iterator<SelectionKey> iter = rdyKey.iterator(); iter
.hasNext();) {
final SelectionKey key = iter.next();
iter.remove();
;
if (key.isValid()) {
if (key.isAcceptable()) {
final ServerSocketChannel ssc = (ServerSocketChannel) key
.channel();
final SocketChannel sc = ssc.accept();
sc.configureBlocking(false);
sc.register(key.selector(), SelectionKey.OP_READ);
} else if (key.isReadable()) {
final SocketChannel sc = (SocketChannel) key.channel();
final int ir = sc.read(buff);
System.out.println(new String(buff.array(), 0, ir));
buff.position(0);
new Thread() {
@Override
public void run() {
try {
Thread.sleep(1000);
key.cancel();
key.attach(null);
sc.socket().close();
sc.close();
} catch (final Exception e) {
e.printStackTrace();
}
}
}.start(); // bug here, but work fine if .run()
} else if (key.isWritable()) {
}
}
}
}
}
}
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-i386
mailing list