Programming Tutorials Browser Tutorials Articles Struts Tutorials Hibernate Tutorials

  Tutorial: Clean Up Your Mess: Managing Temp Files in Java Apps

Clean Up Your Mess: Managing Temp Files in Java Apps Creating and managing temporary files in a Java application can be a little tricky due to some open JVM bugs. Develop a workaround with some custom code and a clever design.

Tutorial Details:

I was always taught to leave a place cleaner than when I got there, and I hold my applications to the same standard. However, a recent Java project I worked on was doing just the opposite, dumping temporary files on the user's system and never cleaning them up. Fearing the inevitable tech support call after the application filled the user's hard disk, I had to fix the problem.
The scenario was simple enough: like many applications, mine had to create temporary files on the user's system during its execution and it then—in theory—would clean them up at exit. The requirement for temporary files (short-lived files normally created in a designated temporary directory) varies from project to project. Applications requiring large batch processing may use temporary files as an intermediate step, while other apps use them to buffer input and output (I/O) from a network or a device. In my case, the temporary files, commonly called temp files, were actually Java Archives (JARs) created at runtime and loaded dynamically into the application (which I later found exasperated the situation). As the project deadline approached, I had to find the problem and, more importantly, develop a solution.
Due to two open Java bugs, a Java application that utilizes a combination of the JVM design and the Win32 operating system does not allow temp files to be deleted if they are open at exit. As a result, the application dumps temporary files on the user's system and never cleans them up.
The JVM can perform a quick cleanup step at startup to delete any temporary files that are lying around from the application's previous run. However, because the temp files must be marked as locked when they are created, put all of the temp files for a given instance of the application into a single directory and lock the directory.


 

Read Tutorial at: Click here to view the tutorial

Rate Tutorial:
Clean Up Your Mess: Managing Temp Files in Java Apps

View Tutorial:
Clean Up Your Mess: Managing Temp Files in Java Apps

Related Tutorials:

Accelerate your Java apps! - JavaWorld - September 1998
Accelerate your Java apps! - JavaWorld - September 1998
 
Java Tip 42: Write Java apps that work with proxy-based firewalls - JavaWorld - December 1997
Java Tip 42: Write Java apps that work with proxy-based firewalls - JavaWorld - December 1997
 
What's new in Java Servlet API 2.2? - JavaWorld October 1999
What's new in Java Servlet API 2.2? - JavaWorld October 1999
 
Java Tip 85: Fun and games with JFileChooser - JavaWorld
Java Tip 85: Fun and games with JFileChooser - JavaWorld
 
Programming XML in Java, Part 1 - JavaWorld March 2000
Programming XML in Java, Part 1 - JavaWorld March 2000
 
Make a sweep with clean beans - JavaWorld November 1999
Make a sweep with clean beans - JavaWorld November 1999
 
Make room for JavaSpaces, Part 6 - JavaWorld October 2000
Make room for JavaSpaces, Part 6 - JavaWorld October 2000
 
Automate your build process using Java and Ant - JavaWorld October 2000
Automate your build process using Java and Ant - JavaWorld October 2000
 
Clean up your wire protocol with SOAP, Part 3 - JavaWorld June 2001
Clean up your wire protocol with SOAP, Part 3 - JavaWorld June 2001
 
JavaMail quick start
JavaMail quick start
 
Java security evolution and concepts, Part 5
Java security evolution and concepts, Part 5
 
Deploy code servers in Jini systems
Deploy code servers in Jini systems
 
Axis: The next generation of Apache SOAP
Axis: The next generation of Apache SOAP
 
Study guide Achieve strong performance with threads Part 1
Study guide Achieve strong performance with threads Part 1
 
Picture this
Picture this
 
Writing Ant Tasks
Writing Ant Tasks A nice feature of Ant is that it is designed to allow you to add your own tasks and use them in an build. This article shows you the basics of writing an Ant task and how to get a task to work.
 
Clean Up Your Mess: Managing Temp Files in Java Apps
Clean Up Your Mess: Managing Temp Files in Java Apps Creating and managing temporary files in a Java application can be a little tricky due to some open JVM bugs. Develop a workaround with some custom code and a clever design.
 
Getting Tidy with Eclipse
In my last article, "Extending Eclipse with Helpful Views," I explained how easy it was to create new functionality in Eclipse. This article continues in the same vein by also creating a new view. However, instead of focusing on the mechanics of writing a
 
Using Timers in J2EE Applications
Using Timers in J2EE Applications Job scheduling is nothing new--most enterprise applications require the scheduling of tasks and activities. For example, your application may need a timer service to run a business process once a day, or to clean up a te
 
Accessing Database from servlets through JDBC!
Accessing Database from servlets through JDBC! Java Servlets J ava Servlets are server side components that provides a powerful mechanism for developing server side of web application. Earlier CGI was developed to provide server side capabilities
 
Site navigation
 

 

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2006. All rights reserved.