Reputation: 9478
I wrote a program that can monitor the folders and let me know changes in those folders.
But this should run whole the day until the system is ON. This should run as a task in background(like batch process).
I am using Java WatchService for monitoring the folders.
I need some suggestions,
Please suggest your ideas.
Thanks
Upvotes: 1
Views: 1536
Reputation: 26703
Q> How can make this as a service that run in background as a batch process?
A> See this SO post, it addresses the same question.
Q> If i make this as service, will this effect the performance of the system? as there will be files added for every 5mins atleast in the folders.
A> Because you are using WatchService
, this should be really cheap. Quoting the documentation:
Most file system implementations have native support for file change notification. The Watch Service API takes advantage of this support where available. However, when a file system does not support this mechanism, the Watch Service will poll the file system, waiting for events.
If in doubt, you can always monitor your server and see how much CPU and I/O your app uses. I bet this won't be a lot.
Upvotes: 3
Reputation: 11298
You can and it should not effect your system performance when your system have enough resource.
Steps to do that in java
FolderMonitor
to monitor a particular folder.
File("C:\folder1")
Map
map key can be a foderName+fileName and value is modified time.ScheduledExecutorService
with required intervalFolderMonitor
class into a jar.Make it service
apache's procrun
or tanukisoftware
service wrapper for creating a service from java executable jar
Hope you can do it. All the best
Upvotes: 3
Reputation: 3088
Make a thread with an infinite loop, like
while(true) {
//code and logic
Thread.sleep(theTimeYouWantBetweenTheScans);
}
Create a .bat file for convinience with stuff, like java -jar myMonitor.jar
The performance depends on your code, but it shouldn't be very heavy. Enjoy.
Upvotes: 0