• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Deleting while using timer

Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
Creativity is allowing yourself to make mistakes; art is knowing which ones to keep. Keep this tiny ad:
a bit of art, as a gift, the permaculture playing cards
    Bookmark Topic Watch Topic
  • New Topic