This is the scenario: I have an xml file that contains information that must be stored, updated or deleted from my database every month. I have taken two approaches to read the file from Java every so often:
- I used a cron with
@Scheduled
and the propertycron
to run it every 30 days. Here I validate the name of the file, if I have the record of the date, I do not read it again. - I used
@EnableBatchProcessing
to execute a process every time the program was executed, foreseeing that the application be deployed every two weeks, again validating if the file was previously read.
However, what they are asking me now is that the file be read every time they deposit a new file in the folder from where I read it and I do not know where to start. Is there in Java something like a "watcher" that is pending from that folder and can read that event (new file deposited in the folder)?