Created
March 27, 2017 18:36
-
-
Save jkutner/bcabf3fc79150088489296180388ef1d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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