Skip to content

Instantly share code, notes, and snippets.

@jkutner
Created March 27, 2017 18:36
Show Gist options
  • Save jkutner/bcabf3fc79150088489296180388ef1d to your computer and use it in GitHub Desktop.
Save jkutner/bcabf3fc79150088489296180388ef1d to your computer and use it in GitHub Desktop.
import java.nio.channels.*;
import java.net.*;
import java.lang.management.*;
import com.sun.management.UnixOperatingSystemMXBean;
import java.net.BindException;
public class TestSocketAccept {
public static void main(String[] args) throws Exception {
OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
UnixOperatingSystemMXBean nix = (UnixOperatingSystemMXBean)os;
for (int offset=0; offset < 64000; offset++){
ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
serverSocketChannel.configureBlocking(false);
try {
serverSocketChannel.socket().bind(new InetSocketAddress("::1", 1080+offset));
SocketChannel socketChannel = serverSocketChannel.accept();
} catch (BindException e) {
// skip
}
System.out.println("count: " + nix.getOpenFileDescriptorCount());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment