打开文件太多<how to =“”find =“”which =“”java =“”file =“”is =“”cause =“”the =“”leak =“”> </how>

时间:2012-09-06 22:57:33

标签: java unix

突然之间,我们在系统中遇到了以下错误。 引起:java.io.FileNotFoundException:/web/wasapps/EventLog.log(打开的文件过多)

我假设有些文件未关闭,但我无法找到导致泄漏的java文件。请帮助我...

Unlimit set如下:

time(seconds)        unlimited
file(blocks)         unlimited
data(kbytes)         unlimited
stack(kbytes)        unlimited
memory(kbytes)       32768
coredump(blocks)     unlimited
nofiles(descriptors) 2000
threads(per process) unlimited
processes(per user)  unlimited

堆栈追踪:

SystemErr R引起:java.io.FileNotFoundException:  /web/wasapps/EventLog.log(太多打开的文件)

at java.io.FileOutputStream.openAppend(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:203)
at java.io.FileOutputStream.<init>(FileOutputStream.java:128)
at com.abc.ci.common.LogManager.writeIntoFile(Unknown Source)
at com.abc.ci.common.LogManager.writeLogFile(Unknown Source)
at com.abc.ci.common.LogManager.handleEvent(Unknown Source)
at com.abc.ci.RANdc.common.CIFAdapter.postRequestForHashMap(Unknown Source)
at com.abc.ci.RANdc.UserInqDataTranslator.translate(Unknown Source)
at com.abc.ci.RANdc.UserInqProcessor.UserInq(UserInqProcessor.java:187)
at com.abc.ci.RANdc.srvprov.UserInqXYHostSrvProv.executeService(Unknown Source)
at com.abc.fiapi.common.XYHostServiceExecutor.execute(Unknown Source)
at com.abc.ci.RAN.ejb.RANModuleEJBBean.executeService(Unknown Source)
at com.abc.ci.srvprov.FRANModuleBeanLookUpServiceProvider.executeService(Unknown Source)
at com.abc.ci.abc.app.abcServiceExecutor.executeService(Unknown Source)
at com.abc.ci.abc.app.abcMessageExecutor.executeService(Unknown Source)
at com.abc.ci.abc.app.abcMessageExecutor.executeMessage(Unknown Source)
at com.abc.ci.abc.app.abcSyncMessageExecutor.processMessage(Unknown 

1 个答案:

答案 0 :(得分:0)

jstack(http://docs.oracle.com/javase/1.5.0/docs/tooldocs/share/jstack.html)也可以帮助确定问题所在。 lsof将为您提供pid,您可以运行jstack < pid >来转储所有线程的堆栈跟踪。假设你在一个循环中打开文件,你可能会抓到一个堆栈,显示你在哪里拿几个jstacks。

另一个解决方案是使用类似JMockit(http://jmockit.googlecode.com)的东西来模拟FileOutputStream构造函数,以便在打开文件时转储​​堆栈。只需将此代码添加到主方法:

final String TARGET_FILE = "/web/wasapps/EventLog.log";
new MockUp<FileOutputStream>()
{
    @Mock
    public $init(Invocation i, String name)
    {
        if (name.equals(TARGET_FILE))
        {
            new Exception().printStackTrace();
        }

        i.proceed();
    }
};