[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

java newbie: a simpler timer

Posted on 2008-06-14
5
Medium Priority
?
258 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
3 Comments
 
LVL 23

Accepted Solution

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

Assisted Solution

by:mbodewes
mbodewes earned 1000 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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month19 days, 8 hours left to enroll

873 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