线程出错(jdom.jar(打开文件过多))

时间:2013-01-14 16:23:43

标签: java multithreading exception struts2

我正在做一个线程来在DB中创建一些插入,而Ajax方法每0.5秒向线程发送一次请求以检查进程。 过了一会儿,我在catalina输出中得到了下一个异常并且线程死了。

任何人都可以向我解释我做错了什么?

我正在使用带有struts 2.0的tomcat 7.

java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor69.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at com.googlecode.jsonplugin.JSONWriter.bean(JSONWriter.java:274)
at com.googlecode.jsonplugin.JSONWriter.process(JSONWriter.java:161)
at com.googlecode.jsonplugin.JSONWriter.value(JSONWriter.java:115)
at com.googlecode.jsonplugin.JSONWriter.array(JSONWriter.java:509)
at com.googlecode.jsonplugin.JSONWriter.process(JSONWriter.java:143)
at com.googlecode.jsonplugin.JSONWriter.value(JSONWriter.java:115)
at com.googlecode.jsonplugin.JSONWriter.add(JSONWriter.java:383)
at com.googlecode.jsonplugin.JSONWriter.bean(JSONWriter.java:275)
at com.googlecode.jsonplugin.JSONWriter.process(JSONWriter.java:161)
at com.googlecode.jsonplugin.JSONWriter.value(JSONWriter.java:115)
at com.googlecode.jsonplugin.JSONWriter.add(JSONWriter.java:383)
at com.googlecode.jsonplugin.JSONWriter.bean(JSONWriter.java:275)
at com.googlecode.jsonplugin.JSONWriter.process(JSONWriter.java:161)
at com.googlecode.jsonplugin.JSONWriter.value(JSONWriter.java:115)
at com.googlecode.jsonplugin.JSONWriter.map(JSONWriter.java:430)
at com.googlecode.jsonplugin.JSONWriter.process(JSONWriter.java:140)
at com.googlecode.jsonplugin.JSONWriter.value(JSONWriter.java:115)
at com.googlecode.jsonplugin.JSONWriter.add(JSONWriter.java:383)
at com.googlecode.jsonplugin.JSONWriter.bean(JSONWriter.java:275)
at com.googlecode.jsonplugin.JSONWriter.process(JSONWriter.java:161)
at com.googlecode.jsonplugin.JSONWriter.value(JSONWriter.java:115)
at com.googlecode.jsonplugin.JSONWriter.write(JSONWriter.java:82)
at com.googlecode.jsonplugin.JSONUtil.serialize(JSONUtil.java:98)
at com.googlecode.jsonplugin.JSONResult.execute(JSONResult.java:179)
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:362)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:266)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:179)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:93)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:130)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(ProfilingActivationInterceptor.java:104)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:165)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:179)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.humanlike.web.interceptors.LoginInterceptor.intercept(LoginInterceptor.java:57)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:468)
at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:964)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:304)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:636)

Caused by: java.io.FileNotFoundException: /usr/local/tomcat_demo/apache-tomcat-7.0.22/webapps/demo2/WEB-INF/lib/jdom.jar (Too many open files)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:137)
at java.io.FileInputStream.<init>(FileInputStream.java:96)
at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:87)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:178)
at java.net.URLConnection.getContent(URLConnection.java:705)
at java.net.URL.getContent(URL.java:1043)
... 92 more

2 个答案:

答案 0 :(得分:1)

您正在使用Struts 2并通过Ajax从客户端发送请求。检查是否确实需要为每个请求创建单独的线程。

Struts 2为每个新请求创建一个新的Action对象。所以我认为你不需要创建线程。

答案 1 :(得分:0)

在linux中打开任何进程的文件数量是有限的。 linux中的文件比Windows更宽(除了普通文件外还有套接字,管道......)。在代码中的某个位置,您打开的文件太多,或者可能是套接字。所以试着找出资源泄漏的位置。