Solved

java newbie: a simpler timer

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Cipher Configuration on Apache HTTPD 4 62
Way to decrease size of apk file 9 69
servlet filter example 37 63
SHA2 certs for IIS AND Java? 2 91
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

777 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