Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Re: Intermittent failure to delete file

Reply
Thread Tools

Re: Intermittent failure to delete file

 
 
John B. Matthews
Guest
Posts: n/a
 
      02-11-2009
In article <(E-Mail Removed)>,
Spud <(E-Mail Removed)> wrote:

> I have a large list of unit tests using JUnit. Many of the tests call
> a method to create a data file, do something to it, and then close
> it. Each test creates the file from scratch so I have a clean version
> of it.
>
> The trouble is that createFile() method fails intermittently because
> it cannot delete the version left over from the previous unit test.
> Sometimes it deletes, sometimes it doesn't.


Just to be sure: Do all tests execute on the same thread?

> I'm guessing that it's an operating system issue. My code closes the
> file, but the OS doesn't. This is Windows, obviously.
>
> Is there any way in Java to tell the OS to commit all changes and
> really close the files?
>
> Or otherwise isolate the unit tests so one doesn't trip up the others?


You might look into File.createTempFile() and deleteOnExit(), as a way
to give each test its own file.

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      02-12-2009
On Wed, 11 Feb 2009 22:31:18 -0600, Spud <(E-Mail Removed)> wrote,
quoted or indirectly quoted someone who said :

>
>Good question. It's possible there's a stray thread hanging around
>longer than it should. Is there any way to know which thread opened a file?


you could create a collection where you track files and threads/open
close status. When you shutdown it should be empty.
--
Roedy Green Canadian Mind Products
http://mindprod.com

"Here is a point of no return after which warming becomes unstoppable
and we are probably going to sail right through it.
It is the point at which anthropogenic (human-caused) warming triggers
huge releases of carbon dioxide from warming oceans, or similar releases
of both carbon dioxide and methane from melting permafrost, or both.
Most climate scientists think that point lies not far beyond 2C (4F) C hotter."
~ Gwynne Dyer
 
Reply With Quote
 
 
 
 
John B. Matthews
Guest
Posts: n/a
 
      02-12-2009
In article <(E-Mail Removed)>,
Spud <(E-Mail Removed)> wrote:

> John B. Matthews wrote:
> > In article <(E-Mail Removed)>,
> > Spud <(E-Mail Removed)> wrote:
> >
> >> I have a large list of unit tests using JUnit. Many of the tests call
> >> a method to create a data file, do something to it, and then close
> >> it. Each test creates the file from scratch so I have a clean version
> >> of it.
> >>
> >> The trouble is that createFile() method fails intermittently because
> >> it cannot delete the version left over from the previous unit test.
> >> Sometimes it deletes, sometimes it doesn't.

> >
> > Just to be sure: Do all tests execute on the same thread?

>
> Good question. It's possible there's a stray thread hanging around
> longer than it should. Is there any way to know which thread opened a file?


I've used lsof to get the process ID:

<http://www.netadmintools.com/html/lsof.man.html>

Of course, one PID may represent several lightweight threads. Would it
help to check Thread.currentThread().holdsLock(file) when file.delete()
returns false?

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Intermittent Failure on Serial Port (Trace Result) H J van Rooyen Python 2 06-13-2006 08:24 AM
Intermittent Failure on Serial Port H J van Rooyen Python 4 06-12-2006 07:05 AM
Intermittent failure to read registry key in ASP.NET application... akhare1 ASP .Net 4 08-01-2004 02:37 AM
Intermittent HDD failure Mike Hayward Computer Support 3 11-15-2003 03:50 AM
Intermittent failure with VPN client on MacOS X.2 Jeff Frontz Cisco 2 08-26-2003 12:30 PM



Advertisments