Skip to content

How do I execute a method at a particular time in java?

Is there any way to write a program in java, so that its main method schedule (or at a 10-15 min interval) another method to executes it at a particular interval?



I think you are looking for the Time class.

See Timer Class API You can use this class like:

You want to perform a Method every 600 miliseconds. You write:

ActionListener taskPerformer = new ActionListener() {
                public void actionPerformed(ActionEvent evt) {  
                //Do your stuff

Timer t = new Timer(600, taskPerfomer);

There are more options. This example will be executed once but it can be executed in an interval. I hope it helps.

6 People found this is helpful