相信很多朋友都遇见过, 一个Java应用长期运行后, 发现jps, jstack, jstat等工具都无法连接正在运行的jvm了。 如果这个时候发生故障, 非常难以诊断。 一直以来, 我都以为是Java的bug.
最近偶然得知, jps的工作模式是读取了系统临时文件夹下的pid文件里的内容获得连接信息的。这个文件夹在Linux下的名字是:/tmp/hsperfdata_$USER ($USER是启动Java程序的用户)。我们都知道系统临时文件夹可能会被某些临时文件夹工具自动删除, 比如:
1. tmpwatch: redhat linux发行版使用的删除工具
2. tmpreaper: ubuntu linux 发行版使用的删除工具
这些工具可能是没有安装的。 那么就不会发生删除/tmp/hsperfdata_$USER的事情。
我们观察到, redhat5.2/5.3 的删除工具的存在一些瑕疵, tmpwatch -umc 会按照最长时间来确定删除。看看umc参数定义:
Java代码
-----------------------------------
If the --atime, --ctime or --mtime options are used in combination, the decision about deleting a file will be based on the maximum of these times.
-----------------------------------
-u, --atime
Make the decision about deleting a file based on the file's atime (access time). This is the default.
Note that the periodic updatedb file system scans keep the atime of directories recent.
-m, --mtime
Make the decision about deleting a file based on the file's mtime (modification time) instead of the atime.
-c, --ctime
Make the decision about deleting a file based on the file's ctime (inode change time) instead of the atime; for
directories, make the decision based on the mtime.
-----------------------------------
① 凡本网注明稿件来源为"原创"的所有文字、图片和音视频稿件,版权均属本网所有。任何媒体、网站或个人转载、链接转贴或以其他方式复制发表时必须注明"稿件来源:我考网",违者本网将依法追究责任;
② 本网部分稿件来源于网络,任何单位或个人认为我考网发布的内容可能涉嫌侵犯其合法权益,应该及时向我考网书面反馈,并提供身份证明、权属证明及详细侵权情况证明,我考网在收到上述法律文件后,将会尽快移除被控侵权内容。