Java process on Mac OSX does not release socket

前端 未结 5 1914
小鲜肉
小鲜肉 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: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

提交回复
热议问题