1

我正在做一个线程来在数据库中创建一些插入,而 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
4

2 回答 2

1

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

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

于 2013-01-14T16:35:06.390 回答
0

在 linux 中任何进程可以打开多少个文件是有限制的。linux 中的文件在某种程度上比 windows 中的要宽(除了普通文件,还有套接字、管道......)。在您的代码中的某处,您打开了太多文件,或者可能是套接字。因此,请尝试找出资源泄漏的位置。

于 2013-01-14T16:28:36.207 回答