Class of the Month: Control Event Executions with the New Timer Class Tennessee

We begin a new column on useful Java classes by looking at Timer and TimerTask, which facilitate execution of code at a predetermined time or during specified time intervals.

Local Companies

Computer Services
615-252-8044
230 Willow St
Nashville, TN
Simple Solutions
(901) 289-0089
4499 Seven Valley Cove
Memphis, TN
Cyberangel Security Solutions Inc
615-837-9191
475 Metroplex DR
Nashville, TN
C M S Manufacturing Systems
615-662-3102
131 Belle Forest Cir
Nashville, TN
Impressive Publshing
423-239-4656
1400 E. Shipley Ferry Rd.
Kingsport, TN
Advanced Technical Services
615-747-5810
200 Hill Ave
Nashville, TN
Expeditors International
(901) 362-9771
5395 Distriplex Farms Drive
Memphis, TN
Advanced Network Solutions
615-277-0500
105 Broadway
Nashville, TN
Peachtree Software Support
615-256-1111
415 4th Ave S
Nashville, TN
Cbnc LLC
615-831-3270
5360 Edmondson Pike
Nashville, TN

provided by: 
Originally published at Internet.com


Amidst all the changes and additions in JDK 1.3, was a small but useful class called Timer. Timer and TimerTask both belong to the java.util package. They facilitate execution of code at a predetermined time or during specified time intervals. In Unix, you can use the "at" command to schedule a process to run at specific times. A similar facility exists under NT servers. There are, however, times when you need to schedule execution of a particular task within a Java program.

Piroz Mohseni

Let's look at a very simple example.

The class ttask inherits from TimerTask and implements a single run() method. Similar to threads, the code inside of the run() method is what is executed on a scheduled basis. In our case, we simply print out a message. Another method that you can implement is cancel(), which stops the task. You only need to call this method once, because after an event is cancelled, it doesn't make sense to cancel it again. You won't get an error, however, if you repeatedly call cancel. It just won't do anything.

Finally, the last method of TimerTask is scheduledExecutionTime(). It returns the scheduled execution time of the task. You can use this value to decide whether you should skip execution or take other actions. If your application requires scheduling and fixed-time execution of tasks, you should take a look at Timer and TimerTask classes...

Read article at Internet.com site

Featured Local Company

Advanced Technical Services

615-747-5810
200 Hill Ave
Nashville, TN

Regional Articles
- Class of the Month: Control Event Executions with the New Timer Class Antioch TN
- Class of the Month: Control Event Executions with the New Timer Class Ashland City TN
- Class of the Month: Control Event Executions with the New Timer Class Brentwood TN
- Class of the Month: Control Event Executions with the New Timer Class Bristol TN
- Class of the Month: Control Event Executions with the New Timer Class Chattanooga TN
- Class of the Month: Control Event Executions with the New Timer Class Clarksville TN
- Class of the Month: Control Event Executions with the New Timer Class Cleveland TN
- Class of the Month: Control Event Executions with the New Timer Class Collierville TN
- Class of the Month: Control Event Executions with the New Timer Class Columbia TN
- Class of the Month: Control Event Executions with the New Timer Class Cookeville TN
- Class of the Month: Control Event Executions with the New Timer Class Cordova TN
- Class of the Month: Control Event Executions with the New Timer Class Crossville TN
- Class of the Month: Control Event Executions with the New Timer Class Dickson TN
- Class of the Month: Control Event Executions with the New Timer Class Dyersburg TN
- Class of the Month: Control Event Executions with the New Timer Class Elizabethton TN
- Class of the Month: Control Event Executions with the New Timer Class Franklin TN
- Class of the Month: Control Event Executions with the New Timer Class Gallatin TN
- Class of the Month: Control Event Executions with the New Timer Class Germantown TN
- Class of the Month: Control Event Executions with the New Timer Class Goodlettsville TN
- Class of the Month: Control Event Executions with the New Timer Class Greeneville TN
- Class of the Month: Control Event Executions with the New Timer Class Harriman TN
- Class of the Month: Control Event Executions with the New Timer Class Hendersonville TN
- Class of the Month: Control Event Executions with the New Timer Class Hermitage TN
- Class of the Month: Control Event Executions with the New Timer Class Hixson TN
- Class of the Month: Control Event Executions with the New Timer Class Humboldt TN
- Class of the Month: Control Event Executions with the New Timer Class Jackson TN
- Class of the Month: Control Event Executions with the New Timer Class Johnson City TN
- Class of the Month: Control Event Executions with the New Timer Class Jonesborough TN
- Class of the Month: Control Event Executions with the New Timer Class Kingsport TN
- Class of the Month: Control Event Executions with the New Timer Class Knoxville TN
- Class of the Month: Control Event Executions with the New Timer Class La Follette TN
- Class of the Month: Control Event Executions with the New Timer Class La Vergne TN
- Class of the Month: Control Event Executions with the New Timer Class Lebanon TN
- Class of the Month: Control Event Executions with the New Timer Class Lenoir City TN
- Class of the Month: Control Event Executions with the New Timer Class Loudon TN
- Class of the Month: Control Event Executions with the New Timer Class Madison TN
- Class of the Month: Control Event Executions with the New Timer Class Martin TN
- Class of the Month: Control Event Executions with the New Timer Class Maryville TN
- Class of the Month: Control Event Executions with the New Timer Class Mc Minnville TN
- Class of the Month: Control Event Executions with the New Timer Class Memphis TN
- Class of the Month: Control Event Executions with the New Timer Class Millington TN
- Class of the Month: Control Event Executions with the New Timer Class Morristown TN
- Class of the Month: Control Event Executions with the New Timer Class Mount Juliet TN
- Class of the Month: Control Event Executions with the New Timer Class Murfreesboro TN
- Class of the Month: Control Event Executions with the New Timer Class Nashville TN
- Class of the Month: Control Event Executions with the New Timer Class Oak Ridge TN
- Class of the Month: Control Event Executions with the New Timer Class Old Hickory TN
- Class of the Month: Control Event Executions with the New Timer Class Ooltewah TN
- Class of the Month: Control Event Executions with the New Timer Class Ripley TN
- Class of the Month: Control Event Executions with the New Timer Class Rogersville TN
- Class of the Month: Control Event Executions with the New Timer Class Sevierville TN
- Class of the Month: Control Event Executions with the New Timer Class Shelbyville TN
- Class of the Month: Control Event Executions with the New Timer Class Signal Mountain TN
- Class of the Month: Control Event Executions with the New Timer Class Smyrna TN
- Class of the Month: Control Event Executions with the New Timer Class Soddy Daisy TN
- Class of the Month: Control Event Executions with the New Timer Class Tullahoma TN

Topics: 
Architecture & Design Languages & Tools Project Management Web Services
Database Microsoft & .NET Security Wireless
Java Open Source Techniques XML