Return-Path: Delivered-To: apmail-jakarta-tomcat-user-archive@apache.org Received: (qmail 5527 invoked from network); 6 Nov 2001 21:45:50 -0000 Received: from unknown (HELO osaka.betaversion.org) (192.18.49.133) by daedalus.apache.org with SMTP; 6 Nov 2001 21:45:50 -0000 Received: (qmail 1242 invoked from network); 6 Nov 2001 21:48:20 -0000 Received: from nagoya.betaversion.org (192.18.49.131) by osaka.betaversion.org with SMTP; 6 Nov 2001 21:48:20 -0000 Received: (qmail 6886 invoked by uid 97); 6 Nov 2001 21:45:13 -0000 Delivered-To: qmlist-jakarta-archive-tomcat-user@jakarta.apache.org Received: (qmail 6870 invoked by uid 97); 6 Nov 2001 21:45:11 -0000 Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tomcat Users List" Reply-To: "Tomcat Users List" Delivered-To: mailing list tomcat-user@jakarta.apache.org Received: (qmail 6859 invoked from network); 6 Nov 2001 21:45:11 -0000 Message-ID: <3BE85858.2040009@gcmd.nasa.gov> Date: Tue, 06 Nov 2001 16:38:32 -0500 From: Chris Gokey Organization: NASA/GCMD User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.2.1) Gecko/20010901 X-Accept-Language: en-us MIME-Version: 1.0 To: Tomcat Users List Subject: Re: Error ajp13_process_callback - write failed References: <764CA2FF49EC054BA086FC8253A52DD7432D10@merc09.na.sas.com> <3BE82BC6.30307@gcmd.nasa.gov> <3BE84C6C.8090604@gcmd.nasa.gov> <025601c1670a$a22b5fd0$ec960040@allegro> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N That's a neat template. Like an event handler to a FileReader! Ok, I'll triple check my source code and make sure all my streams are closed. Thanks, Chris Tom Drake wrote: > Chris: > > You must close your files. Java does not guarantee that > files will be closed automatically. Garbage collection may > reclaim your dangling streams / file handles at some point. > But you cannot say when. You must always close files/urls/etc... > when you are done with them. > > BTW, closing should be done in a finally block like this: > > public void foo (String fileName) throws java.io.IOException{ > java.io.BufferedReader in = null; > > try { > in = new BufferedReader(new java.io.FileReader(fileName)); > for (String line=null; null != (line=in.readLine()); ) { > // do something interesting .... > } > } finally { > if (in != null) { > in.close(); > } > } > } > > Note, the chained Reader objects (e.g. BufferedReader and FileReader). > You must close the 'last' reader / stream that you create. Doing so causes > all other streams / readers in the chained to be closed as well. > > Placing the close() in the finally block ensures that the resource is closed > whether or not an exception is thrown. > > Of course, if you have lots of code that winds up looking like this, you > could use the TemplateMethod pattern to design a solution that allows you > write the resource management code only once and to concentrate on > writing application code. Something like this: > > interface LineHandler { > public void handleLine(String line); > } > > public class MyReader { > ... > public void readFile(String fileName, LineHandler handler) throws > java.io.IOException { > java.io.BufferedReader in = null; > > try { > in = new BufferedReader(new java.io.FileReader(fileName)); > for (String line=null; null != (line=in.readLine()); ) { > handler.handleLine(line); > } > } finally { > if (in != null) { > in.close(); > } > } > } > } > ... > > myReader.readFile("someFileName", new LineHandler() { > public void handleLine(String line) { > // do something interesting with each line. > } > }); > > ----- Original Message ----- > From: "Chris Gokey" > To: "Tomcat Users List" > Sent: Tuesday, November 06, 2001 12:47 PM > Subject: Re: Error ajp13_process_callback - write failed > > > | This time Tomcat crashed, I received some errors... Is it possible to > | receive this kind of error in mod_jk.log if Tomcat can't open up any > | more files? > | > | >>> [Mon Nov 05 06:41:41 2001] [jk_ajp13_worker.c (381)]: Error > | >>> ajp13_process_callback - write failed > | >>> [Mon Nov 05 06:41:58 2001] [jk_ajp13_worker.c (381)]: Error > | >>> ajp13_process_callback - write failed > | >>> [Mon Nov 05 07:19:23 2001] [jk_ajp13_worker.c (381)]: Error > | >>> ajp13_process_callback - write failed > | > | Tomcat would just hang and not serve any more requests. I couldn't > | connect to it directly either via port 8080. > | > | Looking through the logs, this time I noticed I'm getting "too many > | files open" error in my application, so I carefully went through and > | found some instances where files where being opened but not closed. How > | does Java work, if you exit a method will it automatically close the > | file, or does it wait for the garbage collector to do this? I found > | some instances where some servlets didn't explicitly close the > | java.io.Writer from the HttpServletResponse class. > | > | I suppose maybe my application is eating up all the available file > | pointers in memory and tomcat just hung trying to open a file? Is this > | a plausible theory? > | > | Chris > | > | > | Chris Gokey wrote: > | > | > I didn't try that. So far it has been alive all day, so if it crashes > | > again, I'll let you know. Any other logs that might help tell why it is > | > crashing? I don't see much in any of the other logs. Is there a way > | > to increase the verbosity of the logs? > | > > | > Chris > | > > | > Larry Isaacs wrote: > | > > | >> This error occurs when mod_jk tries to write the response back > | >> to the browser. I'm not sure if it is the Ajp13 equivalent > | >> of the "Connection reset by peer" exception when the user clicks > | >> the stop button. > | >> > | >> Does Tomcat still respond after the hang when accessed directly? > | >> > | >> Larry > | >> > | >> > | >>> -----Original Message----- > | >>> From: Chris Gokey [mailto:cgokey@gcmd.gsfc.nasa.gov] > | >>> Sent: Monday, November 05, 2001 6:55 PM > | >>> To: Tomcat Users List > | >>> Subject: Error ajp13_process_callback - write failed > | >>> > | >>> > | >>> Hi, > | >>> > | >>> I've installed Tomcat 3.3 and using mod_jk under Solaris 7. Tomcat > | >>> hung on me twice recently and noticed this error in the mod_jk.log > | >>> before it crashed today. > | >>> > | >>> [Mon Nov 05 06:41:41 2001] [jk_ajp13_worker.c (381)]: Error > | >>> ajp13_process_callback - write failed > | >>> [Mon Nov 05 06:41:58 2001] [jk_ajp13_worker.c (381)]: Error > | >>> ajp13_process_callback - write failed > | >>> [Mon Nov 05 07:19:23 2001] [jk_ajp13_worker.c (381)]: Error > | >>> ajp13_process_callback - write failed > | >>> > | >>> Does anyone know what would cause this error? Also, I don't see > | >>> anything else in the other logs, for that matter that would give me a > | >>> clue. > | >>> > | >>> Thanks, > | >>> Chris > | >>> > | >>> > | >>> -- > | >>> To unsubscribe: > | >>> For additional commands: > | >>> Troubles with the list: > | >>> > | >> > | >> -- > | >> To unsubscribe: > | >> For additional commands: > | >> Troubles with the list: > | >> > | >> > | > > | > > | > > | > > | > | > | > | > | -- > | To unsubscribe: > | For additional commands: > | Troubles with the list: > | > | > | > > > -- > To unsubscribe: > For additional commands: > Troubles with the list: > > -- To unsubscribe: For additional commands: Troubles with the list: