File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Watchdog process to watch a folder" Watch "Watchdog process to watch a folder" New topic

Watchdog process to watch a folder

John Jai

Joined: May 31, 2011
Posts: 1776

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.

Tim Moores

Joined: Sep 21, 2011
Posts: 2409
If you're using Java 7 then you're in luck:
John Jai

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

Joined: Oct 14, 2005
Posts: 19891

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: 10769

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!]
I agree. Here's the link:
subject: Watchdog process to watch a folder
jQuery in Action, 3rd edition