Re: How do I do Socket.select() in java??

Jeff Nisewanger (Jeff.Nisewanger@eng.sun.com)
Wed, 4 Aug 1999 13:12:09 -0700 (PDT)

Message-Id: <199908042013.NAA04091@shorter.eng.sun.com>
Date: Wed, 4 Aug 1999 13:12:09 -0700 (PDT)
From: Jeff Nisewanger <Jeff.Nisewanger@eng.sun.com>
Subject: Re: How do I do Socket.select() in java??
To: java-security@java.sun.com, RDulepet@opticalnetworks.com

> I was wondering how I could wait on multiple sockets with single system call
> in java. What I am looking for is the equivalent functionality to select()
> in winsock.
> http://msdn.microsoft.com/library/sdkdoc/winsock/wsapiref_1ab6.htm
>

All IO in Java is currently "blocking IO". There is no way to
have one thread block waiting for multiple sockets as you can with
non-blocking sockets and select() on win32 or Unix. Instead, you
must create a new thread for each socket that can block in the
IO call (wait for data in read() etc.). Some virtual machine
implementations may have options for tuning thread stack sizes and the
like that can help scale Java to use large numbers of threads.

Although blocking IO is generally simpler and easier to work
with, we realize that this can have scaling limitations to vary large
numbers of sockets and threads. We are currently looking into new IO
models for Java and these may become available in a future release.

By the way, there is another email alias that is devoted
specifically to networking issues. It is java-net@java.sun.com.

Jeff