今天早些时候,我访问了一个我最近启动的网站,页面上充满了一个丑陋的地方jasperexception: java.io.filenotfoundexception: /opt/tomcat/webapps/root/web- inf/lib/jstl-1.2.jar (too many open files)。我检查了我的服务器日志和tomcat日志,它们充满了相同的错误。我增加了tomcat的最大打开文件数限制,以作为一个临时解决方案来保持网站的正常运行,但是它很快又被填满。我已经使用与该网站相同的方法启动了其他网站,以前从未遇到过此问题。这次我唯一不同的是使用Mobirise来为前端制作基本布局,因此我不排除Mobirise使用的某些脚本可能是罪魁祸首。但是,当我得到tomcat已打开的文件列表时,我看到它已经打开了数百个tomcat- users.xml副本,而且它还在不断打开。
jasperexception: java.io.filenotfoundexception: /opt/tomcat/webapps/root/web- inf/lib/jstl-1.2.jar (too many open files)
... java 319 tomcat 935r REG 253,1 2164 263714 /opt/tomcat/conf/tomcat-users.xml java 319 tomcat 936r REG 253,1 2164 263714 /opt/tomcat/conf/tomcat-users.xml java 319 tomcat 937r REG 253,1 2164 263714 /opt/tomcat/conf/tomcat-users.xml java 319 tomcat 938r REG 253,1 2164 263714 /opt/tomcat/conf/tomcat-users.xml java 319 tomcat 939r REG 253,1 2164 263714 /opt/tomcat/conf/tomcat-users.xml java 319 tomcat 940r REG 253,1 2164 263714 /opt/tomcat/conf/tomcat-users.xml java 319 tomcat 941r REG 253,1 2164 263714 /opt/tomcat/conf/tomcat-users.xml java 319 tomcat 942r REG 253,1 2164 263714 /opt/tomcat/conf/tomcat-users.xml java 319 tomcat 943r REG 253,1 2164 263714 /opt/tomcat/conf/tomcat-users.xml java 319 tomcat 944r REG 253,1 2164 263714 /opt/tomcat/conf/tomcat-users.xml java 319 tomcat 945r REG 253,1 2164 263714 /opt/tomcat/conf/tomcat-users.xml java 319 tomcat 946r REG 253,1 2164 263714 /opt/tomcat/conf/tomcat-users.xml java 319 tomcat 947r REG 253,1 2164 263714 /opt/tomcat/conf/tomcat-users.xml java 319 tomcat 948r REG 253,1 2164 263714 /opt/tomcat/conf/tomcat-users.xml java 319 tomcat 949r REG 253,1 2164 263714 /opt/tomcat/conf/tomcat-users.xml java 319 tomcat 950r REG 253,1 2164 263714 /opt/tomcat/conf/tomcat-users.xml java 319 tomcat 951r REG 253,1 2164 263714 /opt/tomcat/conf/tomcat-users.xml java 319 tomcat 952r REG 253,1 2164 263714 /opt/tomcat/conf/tomcat-users.xml java 319 tomcat 953r REG 253,1 2164 263714 /opt/tomcat/conf/tomcat-users.xml java 319 tomcat 954r REG 253,1 2164 263714 /opt/tomcat/conf/tomcat-users.xml java 319 tomcat 955r REG 253,1 2164 263714 /opt/tomcat/conf/tomcat-users.xml java 319 tomcat 956r REG 253,1 2164 263714 /opt/tomcat/conf/tomcat-users.xml java 319 tomcat 957r REG 253,1 2164 263714 /opt/tomcat/conf/tomcat-users.xml java 319 tomcat 958r REG 253,1 2164 263714 /opt/tomcat/conf/tomcat-users.xml java 319 tomcat 959r REG 253,1 2164 263714 /opt/tomcat/conf/tomcat-users.xml java 319 tomcat 960r REG 253,1 2164 263714 /opt/tomcat/conf/tomcat-users.xml java 319 tomcat 961r REG 253,1 2164 263714 /opt/tomcat/conf/tomcat-users.xml java 319 tomcat 962r REG 253,1 2164 263714 /opt/tomcat/conf/tomcat-users.xml java 319 tomcat 963r REG 253,1 2164 263714 /opt/tomcat/conf/tomcat-users.xml java 319 tomcat 964r REG 253,1 2164 263714 /opt/tomcat/conf/tomcat-users.xml ...
我不明白为什么要这么做。我一直在调试,扫描我的代码,并在Internet上搜索tomcat不断打开太多文件的问题,但是它们都只是说“增加最大文件数限制”。它们都没有解决问题的根源,也没有提及任何有关tomcat的事情,只是无限打开单个文件的副本。
[编辑]:这是FileNotFoundException的完整堆栈跟踪:
28-Nov-2018 03:51:33.857 SEVERE [http-nio-8080-exec-5] org.apache.catalina.core.ApplicationDispatcher.invoke Servlet.service() for servlet [jsp] threw exception java.io.FileNotFoundException: /opt/tomcat/webapps/ROOT/WEB-INF/lib/jstl-1.2.jar (Too many open files) at java.util.zip.ZipFile.open(Native Method) at java.util.zip.ZipFile.<init>(ZipFile.java:225) at java.util.zip.ZipFile.<init>(ZipFile.java:155) at java.util.jar.JarFile.<init>(JarFile.java:166) at java.util.jar.JarFile.<init>(JarFile.java:130) at org.apache.tomcat.util.compat.JreCompat.jarFileNewInstance(JreCompat.java:164) at org.apache.tomcat.util.scan.JarFileUrlJar.<init>(JarFileUrlJar.java:65) at org.apache.tomcat.util.scan.JarFactory.newInstance(JarFactory.java:49) at org.apache.tomcat.util.descriptor.tld.TldResourcePath.openJar(TldResourcePath.java:134) at org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:125) at org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:431) at org.apache.jasper.compiler.Parser.parseDirective(Parser.java:489) at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1445) at org.apache.jasper.compiler.Parser.parse(Parser.java:144) at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:244) at org.apache.jasper.compiler.ParserController.parse(ParserController.java:105) at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:206) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:385) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:362) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:346) at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:603) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:400) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330) at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:712) at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:459) at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:384) at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312) at kom.kitten.gingerpage.servlets.HomeServlet.doGet(HomeServlet.java:16) at javax.servlet.http.HttpServlet.service(HttpServlet.java:634) at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at com.googlecode.objectify.ObjectifyFilter.doFilter(ObjectifyFilter.java:48) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:791) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) 28-Nov-2018 03:51:33.859 SEVERE [http-nio-8080-exec-5] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [kom.kitten.gingerpage.servlets.HomeServlet] in conte$ java.io.FileNotFoundException: /opt/tomcat/webapps/ROOT/WEB-INF/lib/jstl-1.2.jar (Too many open files) at java.util.zip.ZipFile.open(Native Method) at java.util.zip.ZipFile.<init>(ZipFile.java:225) at java.util.zip.ZipFile.<init>(ZipFile.java:155) at java.util.jar.JarFile.<init>(JarFile.java:166) at java.util.jar.JarFile.<init>(JarFile.java:130) at org.apache.tomcat.util.compat.JreCompat.jarFileNewInstance(JreCompat.java:164) at org.apache.tomcat.util.scan.JarFileUrlJar.<init>(JarFileUrlJar.java:65) at org.apache.tomcat.util.scan.JarFactory.newInstance(JarFactory.java:49) at org.apache.tomcat.util.descriptor.tld.TldResourcePath.openJar(TldResourcePath.java:134) at org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:125) at org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:431) at org.apache.jasper.compiler.Parser.parseDirective(Parser.java:489) at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1445) at org.apache.jasper.compiler.Parser.parse(Parser.java:144) at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:244) at org.apache.jasper.compiler.ParserController.parse(ParserController.java:105) at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:206) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:385) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:362) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:346) at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:603) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:400) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330) at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:712) at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:459) at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:384) at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312) at kom.kitten.gingerpage.servlets.HomeServlet.doGet(HomeServlet.java:16) at javax.servlet.http.HttpServlet.service(HttpServlet.java:634) at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at com.googlecode.objectify.ObjectifyFilter.doFilter(ObjectifyFilter.java:48) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:791) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748)
这与每次错误发生时(即每次有人尝试在网站上打开的页面,而在tomcat中打开太多文件时)记录的堆栈跟踪相同
这是由Tomcat 9.0.13中的一个错误引起的,该错误已在Tomcat 9.0.14中修复。