nio.Selector behavior?

Erik J Pearson erik.pearson@comcast.net
Wed Oct 29 06:31:00 GMT 2003


(I always try to search the archives to see if this
has been pointed out.  Sorry if it's a duplicate...)

While doing some testing, I was curious if a Selector
could be used for sleeping, like select() when it called
with null parameters except the timeout:

import java.nio.channels.*;

public class Select {

    public static void main(String Args[]) {

        try {
            Selector mySelector = Selector.open();
            // No registered channels
            mySelector.select(10000);
        }
        catch (java.io.IOException IOe) {}
    }
}

Strangely, Sun's java 1.4.2 gives different
results than gij/gcj 3.3.2:

$ time java -cp . Select
 
real    0m10.194s
user    0m0.130s
sys     0m0.040s

$ time gij Select
 
real    0m0.121s
user    0m0.100s
sys     0m0.010s

Without any registered channels gij doesn't try
but java does.

What is the correct behavior?

Thanks in advance.

--erikp--





More information about the Java mailing list