I tried the following:
sudo sysctl -w net.inet.ip.portrange.first=1025
sudo sysctl -w kern.maxfiles=4999999
sudo sysctl -w kern.maxfilesperproc=4999999
for i in `seq 200 230`; do sudo ifconfig lo0 alias 192.168.1.$i ; done
ulimit -n 4999999
But I still get java.io.IOException: Too many open files when I run the test...