• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to monitor a file?

 
scottie zman
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have a perl program that will be updating an XML file at periodic intervals. Then I have a Java program that will go through the XML file and perform some database activity based on the file.
Is there a way to "listen" to the status of the xml file, so that whenever the file gets updated, the java program runs automatically?
My first idea was to just write a loop that waits a few minutes and checks the time on the file, and if it's new then it runs the rest of the program.
I was just wondering if there was a more elegant and instantaneous way of doing this? Any suggestions would be appreciated!
-Zman
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only time I've done anything like this, we used a low level thread that periodically checked the file updated time.

This is a wrapper for java.util.Properties object that caches the values and periodically updates the data. The only bit you should care about is that it is Runnable and checks the file.lastModified()
Help at all?
Dave.
 
scottie zman
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that's good. There's plenty of intersting things in there for me... to get the file attributes, check them, and make a loop to do it every so often. Thanks a lot!
Zman
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!