打开的文件太多:打开的文件数量,打开的数量以及JVM打开的数量 [英] Too many open files: how many are open, what they are, and how many can the JVM open

查看:480
本文介绍了打开的文件太多:打开的文件数量,打开的数量以及JVM打开的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Java中遇到这个异常:

I'm getting this exception in Java:

java.io.FileNotFoundException: (Too many open files) 

我正在寻找消除这个问题的方法。

I'm looking for the ways to eliminate this problem.

这个错误显然表明JVM分配了太多句柄,底层操作系统不会让它拥有更多。要么是因为连接/流不正确而导致泄漏。

This error obviously indicates that JVM has allocated too many handles and underlying OS won't let it have more. Either I've got leak somewhere with improperly closed connections/streams.

这个过程不间断运行几天,最终抛出异常。在12-14天的正常运行时间后会反复发生。

This process runs for days non-stop and eventually throws the exception. It repeatedly happens after 12-14 days of up-time.

你怎么打这个?有没有办法在JVM中获取已分配句柄的列表或在达到一定数量时跟踪?我喜欢打印它们,看它是如何成长的。我不能使用分析器,因为它是一个生产系统,并且难以在开发中重现它。有什么建议吗?

How do you fight this? Is there a way to get a list of allocated handles in JVM or track when it hits certain amount? I'd love to have them printed and see how it grows and when. I can't use a profiler because it's a production system and have difficulties to reproduce it in development. Any suggestion?

我正在监控空闲堆大小并在接近-Xmx中指定总数的1%时发出警报。我也知道如果我的线程数达到500以上,那么肯定会失控。现在,有一种方法可以知道我的JVM从操作系统中分配太多句柄并且不会将其返回,例如套接字,打开的文件等。如果我知道的话,我会知道在哪里以及何时看。

I am monitoring free heap size and raising an "alarm" when it approaches 1% of the total specified in -Xmx. I also know that if my thread count hits above 500, then something definitely goes out of hand. Now, is there a way to know that my JVM allocates too many handles from OS and doesn't give them back, e.g. sockets, opened files, etc. If I'd knew that, I'd know where to look and when.

推荐答案

你没有说你在运行哪个操作系统,但如果你在Linux上运行,你可以使用lsof命令

You didn't say which OS you are running on, but if you are running on Linux you can use the lsof command

lsof -p <pid of jvm>

这将列出JVM打开的所有文件。或者,如果您在Windows上运行,可以 Process Explorer ,它将显示所有内容所有进程的打开文件。

That will list all the files opened by the JVM. Or if you are running on Windows you can Process Explorer which will show all the open files for all the processes.

这样做有望让你缩小代码的哪一部分保持文件打开。

Doing this will hopefully allow you to narrow down which bit of the code is keeping the files open.

这篇关于打开的文件太多:打开的文件数量,打开的数量以及JVM打开的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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