wood burning stoves 2.0*
The moose likes Java in General and the fly likes listener to the folder changes in java application. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "listener to the folder changes in java application." Watch "listener to the folder changes in java application." New topic
Author

listener to the folder changes in java application.

pavithra M K
Greenhorn

Joined: Oct 17, 2006
Posts: 11
Hello,

My requirement in my project to monitor a folder. Whenever a xml file gets added or xml file present in that folder gets updated i need to listen to those changes and parse the xml file to get the message. Do you have clue how we can approch that. I thought of using quartz but schedular will execute the job for every certain interval of time instead of executing the job whenever folder gets modified. Whether can we use joblistener or triggerlistener?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10167
    
    8

You might find this discussion useful.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

Assuming you can be happy with "reasonably quick" notification, say once a minute, its easy.

Better approach is to have a daemon thread sleep, look for file, and if its there, immediately rename it to another directory.
Then release semaphore or other sync technique, to have the "worker" thread do the processing while the "checking" thread takes a nap and does the next lookup.

Its only 30 or so lines of code.
pavithra M K
Greenhorn

Joined: Oct 17, 2006
Posts: 11
Thank you all for your replies.

i have thought of using JDK1.7 API's for folder monitoring, however JDK1.7 is not yet released we cannot suggest this to customers. And we dont want to use Threads here.

Can i use quartz- job, schedular and trigger listener in this scenario.

JOb -to read the xml file.
trigger listener - to listen to the folder changes and execute the Job.

Actually i want to know how to use trigger listener or job listener or schedule listener in my Java Application.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37926
    
  22
Pavithra M K please read the important administrative private message I just sent you.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: listener to the folder changes in java application.
 
Similar Threads
404 error on servlet due to "requested resource not available"
regarding JDK1.7 release
Problem in configuring Oracle 10g data source in JBOSS.
Reload/Compile Jsp pages after updating XML file on webserver
copy netbeans project fiel