Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Watchdog process to watch a folder

 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 2895
46
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're using Java 7 then you're in luck: http://download.oracle.com/javase/tutorial/essential/io/notification.html
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh No!! The production version is Java 1.6...
 
Paul Clapham
Sheriff
Posts: 21316
32
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11092
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Jai wrote:Oh No!! The production version is Java 1.6...

In the past I have successfully used JNotify
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic