Finding out what network sockets are open in the current Java VM

前端 未结 2 1338
我寻月下人不归
我寻月下人不归 2020-12-13 09:58

I\'m writing an end-to-end test that my Java program releases all of its resources - threads, server sockets, client sockets. It\'s a library, so releasing resources by exit

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-13 10:37

    I haven't tried it myself, but the JavaSpecialists newsletter presents a similar problem:

    http://www.javaspecialists.eu/archive/Issue169.html

    At the bottom, he describes an approach using AspectJ. You could probably put the pointcut around the constructor that creates the socket, and have code that registers socket creation there.

提交回复
热议问题