Date: Mon, 15 Aug 2011 10:26:01 GMT From: arli weng <url@163.com> To: freebsd-gnats-submit@FreeBSD.org Subject: i386/159787: openjdk 1.6 nio muti-thread bug Message-ID: <201108151026.p7FAQ1Ux069072@red.freebsd.org> Resent-Message-ID: <201108151030.p7FAUAWJ075395@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>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@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:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201108151026.p7FAQ1Ux069072>