Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Deleting while using timer  RSS feed

Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a TimerTask that looks for a file on a directory. Once it sees
the file, it parses it and puts it in the DB using several objects.
After all of that is done, the system is supposed to delete the file
so that it does not just sit there parsing it. But, there seems to be
a lock on the directory. I can't even delete it manually when
the timertask is polling.

How do I kill the timertask long enough to delete a file through
the software using: boolean isDeleted = file.delete();? No one
monitors these directories. I have created a system that allows files
to be uploaded to the hard drive (automatically) and then once parsed,
I need the files to be killed or my timer will just keep parsing the
files over and over again. Any thoughts? The code that is not working
is below.

In summary, Another class (not shown) invokes the TimeLapFiles class.
That class is the invoker. It polls every 10 seconds. The file
takes miliseconds to process so there should be no use of the file by
the time that the delete method is called. But the lock on the
directory won't allow any delete at all.

For those of you form the US, happy 4th!

[ July 01, 2005: Message edited by: Al Wells ]
Author and all-around good cowpoke
Posts: 13078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That syntax for File depends on the "current" directory not the root directory - you may not be getting a valid File object. Also, I don't see where you close readLap - so your program still has the file open, creating a lock.
Wouldn't it be simpler to have the parsing program close and delete the file directly?
They gave me pumpkin ice cream. It was not pumpkin pie ice cream. Wiping my tongue on this tiny ad:
Rocket Oven Kickstarter - from the trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!