I have a Java Spring (MVC) servlet and I need to create a slow, long running process that would create entries in the database over time. The servlet should provide view to the database content, also some information about the status of the process.
The process is not computation intensive but it takes ages. It is very likely that I will need to restart the servlet even multiple times while it is running. The process is capable of making check points, but a known code must be called to make and apply them. The process creates entries in the database, and it is possible and required to monitor its activity this way.
So far I consider the following ideas:
- A separate Java program, controlled by Linux Cron.
- An ExecutorService, attached to the static field inside the servlet class.
- A Spring bean that starts activities from the @PostConstruct method.
- Spring Batch framework may be possible, but I am not sure if it is not too heavy for that I need.
I do not know, maybe this is "opinion based", but the situation could be frequent and I would like to know a typical good solution that should be considered professionally implemented.