Java process on Mac OSX does not release socket

前端 未结 5 1927
小鲜肉
小鲜肉 2021-02-14 00:00

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

相关标签:
5条回答
  • 2021-02-14 00:29

    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?

    0 讨论(0)
  • 2021-02-14 00:32

    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.

    0 讨论(0)
  • 2021-02-14 00:39

    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.

    0 讨论(0)
  • 2021-02-14 00:44

    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

    0 讨论(0)
  • 2021-02-14 00:52

    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.

    0 讨论(0)
提交回复
热议问题