Answer your first question "how to run a Java class in a certain interval?"
You can use quartz triggers to run a Java class on a time interval.
Second question: "what if the connection is lost?"
Check the class that runs in the time interval for connecting, if you open it, and then do not try to connect, and if it is lost, first connect to db, and then update db.
Third question: "Should the connection remain open every time?"
If you want to update with a very short period of time, then I think that yes, you should keep it open. But not sure about that. Maybe you should try to save it.
source share