I am developing a rather complex web application that calls several processes that are executed externally, the background process grails and reads / writes from / to several files - all in one controller. Everything was fine until I checked it with many requests in close proximity. When I do this, I get the following java error message in the tomcat catalina log file:
WARNING: Exception executing accept
java.net.SocketException: Too many open files
at java.net.PlainSocketImpl.socketAccept(Native Method)
at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:408)
at java.net.ServerSocket.implAccept(ServerSocket.java:462)
at java.net.ServerSocket.accept(ServerSocket.java:430)
at org.apache.jk.common.ChannelSocket.accept(ChannelSocket.java:312)
at org.apache.jk.common.ChannelSocket.acceptConnections(ChannelSocket.java:666)
at org.apache.jk.common.ChannelSocket$SocketAcceptor.runIt(ChannelSocket.java:877)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)
at java.lang.Thread.run(Thread.java:662)
At first, after some happy googeling and reading, I suspected that this might be a "system problem", that is, I need to increase the limit for open files for the user who is running tomcat, but it is not.
Java, Grails Groovy, Google Grails, . , " " ( - ) ( ).
:
1) :
def someFile = new File("/some/file.txt")
someFile << "Some content\n"
2) :
def cmd = "bash some-cmd".execute()
cmd.waitFor()
3) :
def fileContent = new File("/some/file.txt").text
4) :
def URL url = new URL("http://www.some.link");
def URLConnection uc = url.openConnection()
def BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream()))
...
br.close()
, , , BufferedReader InputStream, , br.close() .
: ? ? , ", "?
" " ? IOException: .
grails 1.1.1 ( , , , ), groovy 1.8.0, tomcat 6.0.28, apache 2.2.16 ubuntu 10.10.
" " . , BufferedReader. Java- grails:
def URL url = new URL("http://www.some.link");
def URLConnection uc = url.openConnection()
def BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream()))
try{
...
}finally{
br.close()
}
- > " ", , .