java - Reading from new folders every x seconds and using their data -


currently writing application in java looks through files in directory (call 'topics'). within directory number of folders named after respective topics, maybe 'dog', 'cat', etc.

i using scheduledexecutorservice through directory every 30 seconds, going through each topic folder , performing operation on contents in folder (we'll other independent piece of code writing these topic folders, maybe log file or something).

what best way examine new subdirectories each 30 seconds? if start topic dog, , somewhere between 30 seconds topics 'cat' , 'bird' added, best way me through new folders? thinking comparing hashset or something, i'm not sure efficient way this.

i ask because there potentially great amount of subdirectories being created, , seems me problematic try loop through each 1 directory.listfiles(). advice?

use java's watchservice api.

the watchservice api low level, allowing customize it. can use is, or can choose create high-level api on top of mechanism suited particular needs. - java docs

when watchservice detects file or directory change can notify of watch file or directory changed giving path it. using api don't have worry comparing 2 lists see changed because api provides path of changed file.

take @ java tutorial "watching directory changes" oracle on using watchservice api.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -