I have developed a REST-ful web service using Jersey in Java. It is basically a JSON service wrapped around scraped web data. At the moment I serialize my entire scraped data set (A Set<Object>
) to a file and when the user requests data I load it from disk and deserialize it. The web application will probably be running on a Tomcat server.
However, this data might change at any point during the day so I would like to update it every n
hours. I know how to update the file periodically (e.g., a ScheduledExecutorService
) but I'm unsure where I would execute the code due to not being familiar with the flow of a Tomcat server.
For example, as per this article it would be a bad idea to execute the ScheduledExecutorService
in the resource class as it is created per user request.
Any help is greatly appreciated.