java newbie: a simpler timer

I need a very simpler timer to call a function every 5 minutes in JAVA.
Just standard JAVA libs.
yarekAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Ajay-SinghConnect With a Mentor Commented:
0
 
mbodewesConnect With a Mentor Commented:
The above is a solution (and a good one at that). You may also use Thread.sleep() to suspend the running Thread for a (long) amount of milliseconds. From the top of my head that would be 5 * 60 * 1000 is 300,000 milliseconds. It depends on how you want to do it, the Timer class uses a background thread so you can keep doing things, the Thread.sleep() method stops all execution until it runs out of time or until it is woken up by another Thread.
0
 
shaz_Commented:

public class Monitor extends Thread{
 
public startMonitoring(){
  this.start();
}
 
public void run(){
  methodToCall(); 
  thread.sleep(300000);// 5mins in milliseconds(i hope)
   
}
}

Open in new window

0
All Courses

From novice to tech pro — start learning today.