Scheduling a task
I have a class written in Java that connects to a MySQL database and updates few tables. It works perfectly fine.
I have to run it after every 4 hours. I want to automate it using some scheduling. How can this be done. Please help me out.
Thanks a lot.
You can create a java.util.TimerTask implementation that do your database update. Then run this task using java.util.Timer class every 4 hours as you required. I have a small example on how to use these classes here: How do I create a scheduled task using timer? You can just modified it to fit your requirement.
But I don't wan to run the code my self. I want some background process to keep monitoring the time and after 4 hours, it should trigger the class.
Something like Window Scheduling.
Well, there must be an application to execute the job right. This application can be your own java class or maybe you can also execute it from the windows scheduler. If it can run any command line you can ask the windows scheduler to execute java command to run your class.
There is also some great library for scheduling such as Quartz that you can also use for creating the scheduler.