permaculture playing cards*
The moose likes Java in General and the fly likes Watchdog process to watch a folder Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Watchdog process to watch a folder" Watch "Watchdog process to watch a folder" New topic
Author

Watchdog process to watch a folder

John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Hi,

I want to develop a program to watch a configured folder. If files are copied into the folder, I need to trigger a set of processes with the copied files.

My current thought is to write a Thread that checks the folder for new files placed. The Thread will sleep for configured time between each poll. I do not want to do this approach since I have to keep list of old files processed to know which are the new files that should be processed. And I feel there will not be instant processing of placed files due to intermittent sleep applied on the Thread.

I need a thing like JMS / EJB (Message Driven bean) in simple core Java. I might be wrong here. Let me know if you have any suggestions.

Thanks!
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
If you're using Java 7 then you're in luck: http://download.oracle.com/javase/tutorial/essential/io/notification.html
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Oh No!! The production version is Java 1.6...
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

In most operating systems the "Last Active Date" of a folder is changed whenever a new file is created in that folder. This means you don't need to keep track of what files are in the folder at any time. Just keep track of the folder's last active date.

There are also people who have written implementations of this process which work with pre-Java-7 versions, using JNI to access folder-monitoring services from the O/S. You could track them down on the web, I don't remember any names.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10268
    
    8

John Jai wrote:Oh No!! The production version is Java 1.6...

In the past I have successfully used JNotify


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
 
wood burning stoves
 
subject: Watchdog process to watch a folder