Solved

java newbie: a simpler timer

Posted on 2008-06-14
5
231 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
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

759 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now