I am experiencing an odd problem every now and then (too often actually).
I am running a server application, which is binding a socket for itself.
But once in a
I have also Parallels, and often the problem looks like it's caused by the Parallels network adapter....
I'd say that's a fair bet if this problem is not cropping up on other platforms. What have you done to exclude Parallels as the culprit?
So it seems that the problem lies in the implementation of Selector in the Mac version of JDK 6. Installing the new Oracle JDK 7u4 fixes the issue, independent of how the Selector is used.
Just a shot in the dark here, but make sure that any thread that is waiting on Selector.select() has been woken up, and has exited.
if you think that the resources are not properly released, you can try to do the release in a shutdownhook. like this at least when its shut down the resouces will be released (not though if you hard kill)
an example for a very basic shutdownhook:
public void shutDownProceedure(){
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
/* my shutdown code here */
}
});
}
This helped me release resources that somehow weren't entirely released before. I don't know if this works for sockets as well, i think it should.
It also allowed me to see loggings i haven't seen before
try closing the socket with http://docs.oracle.com/javase/1.4.2/docs/api/java/net/ServerSocket.html#close() after each test, in the teardown, if you're not already.