• Post Reply Bookmark Topic Watch Topic
  • New Topic

WatchService to return something on a continuous basis to trigger something  RSS feed

 
Faraz Ka
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a requirement where I have to call some method based on the changes in the filesystem. I just had a quick look into the WatchService API of Java7 but not sure if it returns something ( variable or object) while in the process of listening, that can be read to trigger another call.
Any hints here will be highly appreciated.

Thanks.
FKA
 
Knute Snortum
Sheriff
Posts: 4279
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you read this? http://docs.oracle.com/javase/tutorial/essential/io/notification.html
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Faraz Ka wrote: have a requirement where I have to call some method based on the changes in the filesystem. I just had a quick look into the WatchService API of Java7 but not sure if it returns something ( variable or object) while in the process of listening, that can be read to trigger another call.

I'm pretty sure it does.

The only thing I would suggest is that you may want to think carefully about this business of "continuous". "Busy" checkers (ie, ones that constantly monitor something, and maintain a state based on what they're monitoring) can be quite resource-intensive; and they can often be substituted with a "passive" check (ie, one that only does a check on request) that may also be able to give you more "up-to-date" results.

The choice will depend on your requirements - obviously, if you have a million requests a second, you might not want to deal with each one individually; but if they're only once an hour, then a passive approach may well be better.

I'm not familiar enough with the WatchService API to know how it works, but I suspect that the docs will tell you. It may even support both approaches.

HIH

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!