Solved

java newbie: a simpler timer

Posted on 2008-06-14
5
246 Views
Last Modified: 2013-11-23
I need a very simpler timer to call a function every 5 minutes in JAVA.
Just standard JAVA libs.
0
Comment
Question by:yarek
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 23

Accepted Solution

by:
Ajay-Singh earned 250 total points
ID: 21784686
0
 
LVL 9

Assisted Solution

by:mbodewes
mbodewes earned 250 total points
ID: 21787010
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
 
LVL 3

Expert Comment

by:shaz_
ID: 21845109

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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn different types of Android Layout and some basics of an Android App.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question