java left logo
java middle logo
java right logo
 

Home arrow Java SE Tips arrow java.util arrow How to set a timer for a task to run at a specific time
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4092
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
How to set a timer for a task to run at a specific time E-mail
User Rating: / 61
PoorBest 

This Java tip illustrates a method of scheduling a timer for a task to run at a certain time. Developer may use this code if there is a need to execute or repeat a task in an application at a predefined interval of time.

    int interval = 10000// 10 sec
    Date timeToRun = new Date(System.currentTimeMillis() + interval);
    Timer timer = new Timer();
    
    timer.schedule(new TimerTask() {
            public void run() {
                // Task here ...
            }
        }, timeToRun);

 Related Tips

 
< Prev   Next >
 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.