File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

listener to the folder changes in java application.

 
pavithra M K
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10971
11
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might find this discussion useful.
 
Pat Farrell
Rancher
Posts: 4660
5
Linux Mac OS X VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pavithra M K please read the important administrative private message I just sent you.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic