This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Servlets and the fly likes when PrintWriter.flush() is called Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "when PrintWriter.flush() is called" Watch "when PrintWriter.flush() is called" New topic
Author

when PrintWriter.flush() is called

Edy Yu
Ranch Hand

Joined: Nov 21, 2000
Posts: 264
I'll assume that the servlet container will call the flush() or close() method sometime while serving a request to one servlet because we don't have to code close() or flush() in our code. Does anyone know when this "commit" happens?
Thanks in advcance ...


<i><br />Sun Certified Programmer for Java 2 Platform (SCJP)<br />Sun Certified Developer for Java 2 Platform (SCJD)<br />Sun Certified Web Component Developer for Java2 Platform, Enterprise Edition (SCWCD)<br />Sun Certified Business Component Developer for Java2 Platform, Enterprise Edition (SCBCD)<br />Sun Certified Enterprise Architect for J2EE (SCEA)<br />IBM Certified Enterprise Developer, WebSphere Studio V5.0<br /></i>
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12678
    
    5
Personally I always prefer to code an explicit out.close(). With earlier versions of Tomcat, this solved some mysterious blank pages, so ever since then I have used an explicit close(). I don't think you can depend on close being called automatically in servlets.
I know that the finalize methods for various java.io streams call close, so I suppose that garbage collection would eventually force it.
Bill


Java Resources at www.wbrogden.com
 
 
subject: when PrintWriter.flush() is called
 
Similar Threads
file created,but nothing inside
Login code problem
Servlet to Applet communication
InterruptedIOException: Read timed out
When to use flush() in Java?