JVM异常退出-清理系统资源 [英] JVM abnormal exit - cleanup of system resources

查看:257
本文介绍了JVM异常退出-清理系统资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java程序,它具有无限侦听服务器套接字的功能. 如果JVM通过kill pid异常退出,那么在这种情况下,套接字对象会对系统资源产生什么影响?插座会被释放还是被锁住?

I have a java program which has a server-socket listening infinitely. In case of JVM exiting abnormally through kill pid, what happens to system resources in this case, socket object ? Will the sockets be released or it will be locked up?

在异常的JVM退出的情况下,处理文件描述符/网络套接字/jdbc连接之类的系统资源的最佳方法是什么.

What is the best way to handle the cleanup of system resources like file descriptors/network-socket/jdbc connection, in case of abnormal JVM exit.

我最终了解终结器,但是使用终结器会带来一些不确定性和性能下降.

I know about finalizers, finally, but there is some amount of uncertainty and performance degradation using finalization.

请提供一些想法

推荐答案

在异常退出的情况下,显然JVM不能做任何专门的事情来清理已分配的内容.这种责任将落在操作系统本身旁边.

In the case of an abnormal exit, obviously the JVM can't do anything specifically to clean up whatever it has allocated. This responsibility would fall next to the operating system itself.

对于套接字,现代操作系统肯定会释放由崩溃进程打开的所有套接字.这同样适用于文件和任何其他内核对象(JDBC连接是通过某种套接字实现的.)

For sockets, modern operating systems will definitely release any sockets that had been opened by a process that crashes. The same applies to files and any other kernel objects (JDBC connections are implemented with some sort of socket).

如果JVM异常终止,则终结器将不会运行.

Finalizers will not be run if the JVM terminates abnormally.

这篇关于JVM异常退出-清理系统资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆