我只是让我系统的所有用户尝试同时登录。我的服务器因这个错误而崩溃:
SEVERE: Socket accept failed
Throwable occurred: java.net.SocketException: Too many open files
at java.net.PlainSocketImpl.socketAccept(Native Method)
at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:449)
at java.net.ServerSocket.implAccept(ServerSocket.java:473)
at java.net.ServerSocket.accept(ServerSocket.java:441)
at org.apache.tomcat.util.net.DefaultServerSocketFactory.acceptSocket(DefaultServerSocketFactory.java:59)
at org.apache.tomcat.util.net.JIoEndpoint$Acceptor.run(JIoEndpoint.java:212)
at java.lang.Thread.run(Thread.java:736)
May 9, 2012 10:04:11 AM org.apache.tomcat.util.net.JIoEndpoint$Acceptor run
我运行了一个 lsof 命令来查看 tomcat 用户打开了哪些文件,并得到了一个巨大的文件列表。大多数看起来很正常,但后来我遇到了大约 700 个相同文件的条目,这是该输出的一个片段:
java 12285 tomcat 256r REG 8,3 1470076 1040880 /usr/share/tomcat7/shared/nmsc/icefaces-ace-3.0.0.RC2.jar
java 12285 tomcat 257r REG 8,3 1955103 1040820 /usr/share/tomcat7/shared/nmsc/jsf-impl-2.1.4.jar
java 12285 tomcat 258r REG 8,3 1955103 1040820 /usr/share/tomcat7/shared/nmsc/jsf-impl-2.1.4.jar
java 12285 tomcat 259r REG 8,3 271669 1040879 /usr/share/tomcat7/shared/nmsc/icefaces-3.0.0.RC2.jar
java 12285 tomcat 260r REG 8,3 1470076 1040880 /usr/share/tomcat7/shared/nmsc/icefaces-ace-3.0.0.RC2.jar
java 12285 tomcat 261r REG 8,3 1470076 1040880 /usr/share/tomcat7/shared/nmsc/icefaces-ace-3.0.0.RC2.jar
java 12285 tomcat 262r REG 8,3 1470076 1040880 /usr/share/tomcat7/shared/nmsc/icefaces-ace-3.0.0.RC2.jar
java 12285 tomcat 263r REG 8,3 1470076 1040880 /usr/share/tomcat7/shared/nmsc/icefaces-ace-3.0.0.RC2.jar
java 12285 tomcat 264r REG 8,3 1470076 1040880 /usr/share/tomcat7/shared/nmsc/icefaces-ace-3.0.0.RC2.jar
java 12285 tomcat 265r REG 8,3 1470076 1040880 /usr/share/tomcat7/shared/nmsc/icefaces-ace-3.0.0.RC2.jar
java 12285 tomcat 266r REG 8,3 1470076 1040880 /usr/share/tomcat7/shared/nmsc/icefaces-ace-3.0.0.RC2.jar
java 12285 tomcat 267r REG 8,3 1470076 1040880 /usr/share/tomcat7/shared/nmsc/icefaces-ace-3.0.0.RC2.jar
java 12285 tomcat 268r REG 8,3 1470076 1040880 /usr/share/tomcat7/shared/nmsc/icefaces-ace-3.0.0.RC2.jar
java 12285 tomcat 269r REG 8,3 1955103 1040820 /usr/share/tomcat7/shared/nmsc/jsf-impl-2.1.4.jar
java 12285 tomcat 270r REG 8,3 1955103 1040820 /usr/share/tomcat7/shared/nmsc/jsf-impl-2.1.4.jar
java 12285 tomcat 271r REG 8,3 271669 1040879 /usr/share/tomcat7/shared/nmsc/icefaces-3.0.0.RC2.jar
java 12285 tomcat 272r REG 8,3 1470076 1040880 /usr/share/tomcat7/shared/nmsc/icefaces-ace-3.0.0.RC2.jar
java 12285 tomcat 273r REG 8,3 1470076 1040880 /usr/share/tomcat7/shared/nmsc/icefaces-ace-3.0.0.RC2.jar
java 12285 tomcat 274r REG 8,3 271669 1040879 /usr/share/tomcat7/shared/nmsc/icefaces-3.0.0.RC2.jar
java 12285 tomcat 275r REG 8,3 1955103 1040820 /usr/share/tomcat7/shared/nmsc/jsf-impl-2.1.4.jar
java 12285 tomcat 276r REG 8,3 1470076 1040880 /usr/share/tomcat7/shared/nmsc/icefaces-ace-3.0.0.RC2.jar
java 12285 tomcat 277r REG 8,3 1955103 1040820 /usr/share/tomcat7/shared/nmsc/jsf-impl-2.1.4.jar
java 12285 tomcat 278r REG 8,3 271669 1040879 /usr/share/tomcat7/shared/nmsc/icefaces-3.0.0.RC2.jar
java 12285 tomcat 279r REG 8,3 1470076 1040880 /usr/share/tomcat7/shared/nmsc/icefaces-ace-3.0.0.RC2.jar
java 12285 tomcat 280r REG 8,3 1470076 1040880 /usr/share/tomcat7/shared/nmsc/icefaces-ace-3.0.0.RC2.jar
java 12285 tomcat 281r REG 8,3 1955103 1040820 /usr/share/tomcat7/shared/nmsc/jsf-impl-2.1.4.jar
java 12285 tomcat 282r REG 8,3 1470076 1040880 /usr/share/tomcat7/shared/nmsc/icefaces-ace-3.0.0.RC2.jar
java 12285 tomcat 283r REG 8,3 271669 1040879 /usr/share/tomcat7/shared/nmsc/icefaces-3.0.0.RC2.jar
java 12285 tomcat 284r REG 8,3 1470076 1040880 /usr/share/tomcat7/shared/nmsc/icefaces-ace-3.0.0.RC2.jar
java 12285 tomcat 285r REG 8,3 1955103 1040820 /usr/share/tomcat7/shared/nmsc/jsf-impl-2.1.4.jar
我增加了 tomcat 用户允许的文件句柄数量,以便让我度过早上,但是为什么 tomcat 会为每个 HTTP 请求(这似乎是正在发生的事情)打开一个新的 icefaces 和 jsf 副本而不是使用类加载器在启动时加载的文件副本?我什至不知道从哪里开始解决这个问题。