This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes How do I close an opened XML-file I just read? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "How do I close an opened XML-file I just read?" Watch "How do I close an opened XML-file I just read?" New topic
Author

How do I close an opened XML-file I just read?

Robert Jaeger
Ranch Hand

Joined: Apr 29, 2002
Posts: 62
Hi!
I am using the following code to open XML files:

Now, after surfing on the webpages for a while(generated with jsp, content source is XML) Tomcat reported that too many documents are opened. I had to restart Tomcat.
So do I have to explicitly close the xml-files? How?
Thanks for your help,
Robert.
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
Don't be lazy, construct a FileReader first, after build, close it. This will solve too many files open problem. This is extremely important to busy websites. The resources will be used really quickly. You don't DOS (deny of services) by your own mistake. You original code will never close the valuable resources.
All 60 files are closed after build, but all Documents are still available for traversal.
See complete tested code here:
http://bobcat.webappcabaret.net/javachina/faq/xml_java_01.htm#jaxp_jdom_Q30
[ April 12, 2003: Message edited by: Roseanne Zhang ]
 
 
subject: How do I close an opened XML-file I just read?