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

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

Cms Software
313-965-4775
500 Griswold St
Detroit, MI
All About Technology
313-962-2430
2727 2nd Ave
Detroit, MI
L & M Office Products
313-861-5707
8514 W Mcnichols RD
Detroit, MI
Sync Technologies
313-963-5353
2727 2nd Ave
Detroit, MI
PC Menders Computer Services
313-397-2713
18256 Grand River Ave
Detroit, MI
Corporate IT Source
248-396-1573
6841 N. Rochester Rd.
Rochester Hills, MI
Protocol Syst C
313-534-8773
18201 W 8 Mile Rd
Detroit, MI
Computer Power Store
313-640-4681
15411 Mack Ave
Detroit, MI
Keane Inc
248-356-2000
3000 Northwestern St
Detroit, MI
Woodwing USA
313-962-0542
615 Griswold St
Detroit, MI

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

Corporate IT Source

248-396-1573
6841 N. Rochester Rd.
Rochester Hills, MI

Regional Articles
- Class of the Month: Control Event Executions with the New Timer Class Adrian MI
- Class of the Month: Control Event Executions with the New Timer Class Allegan MI
- Class of the Month: Control Event Executions with the New Timer Class Allen Park MI
- Class of the Month: Control Event Executions with the New Timer Class Alpena MI
- Class of the Month: Control Event Executions with the New Timer Class Ann Arbor MI
- Class of the Month: Control Event Executions with the New Timer Class Auburn Hills MI
- Class of the Month: Control Event Executions with the New Timer Class Battle Creek MI
- Class of the Month: Control Event Executions with the New Timer Class Bay City MI
- Class of the Month: Control Event Executions with the New Timer Class Belleville MI
- Class of the Month: Control Event Executions with the New Timer Class Benton Harbor MI
- Class of the Month: Control Event Executions with the New Timer Class Berkley MI
- Class of the Month: Control Event Executions with the New Timer Class Big Rapids MI
- Class of the Month: Control Event Executions with the New Timer Class Bloomfield Hills MI
- Class of the Month: Control Event Executions with the New Timer Class Brighton MI
- Class of the Month: Control Event Executions with the New Timer Class Burton MI
- Class of the Month: Control Event Executions with the New Timer Class Cadillac MI
- Class of the Month: Control Event Executions with the New Timer Class Canton MI
- Class of the Month: Control Event Executions with the New Timer Class Cheboygan MI
- Class of the Month: Control Event Executions with the New Timer Class Clarkston MI
- Class of the Month: Control Event Executions with the New Timer Class Clinton Township MI
- Class of the Month: Control Event Executions with the New Timer Class Clio MI
- Class of the Month: Control Event Executions with the New Timer Class Coldwater MI
- Class of the Month: Control Event Executions with the New Timer Class Commerce Township MI
- Class of the Month: Control Event Executions with the New Timer Class Comstock Park MI
- Class of the Month: Control Event Executions with the New Timer Class Davison MI
- Class of the Month: Control Event Executions with the New Timer Class Dearborn Heights MI
- Class of the Month: Control Event Executions with the New Timer Class Dearborn MI
- Class of the Month: Control Event Executions with the New Timer Class Detroit MI
- Class of the Month: Control Event Executions with the New Timer Class Dowagiac MI
- Class of the Month: Control Event Executions with the New Timer Class East Lansing MI
- Class of the Month: Control Event Executions with the New Timer Class Eastpointe MI
- Class of the Month: Control Event Executions with the New Timer Class Eaton Rapids MI
- Class of the Month: Control Event Executions with the New Timer Class Escanaba MI
- Class of the Month: Control Event Executions with the New Timer Class Farmington MI
- Class of the Month: Control Event Executions with the New Timer Class Fenton MI
- Class of the Month: Control Event Executions with the New Timer Class Ferndale MI
- Class of the Month: Control Event Executions with the New Timer Class Flat Rock MI
- Class of the Month: Control Event Executions with the New Timer Class Flint MI
- Class of the Month: Control Event Executions with the New Timer Class Flushing MI
- Class of the Month: Control Event Executions with the New Timer Class Fort Gratiot MI
- Class of the Month: Control Event Executions with the New Timer Class Fraser MI
- Class of the Month: Control Event Executions with the New Timer Class Garden City MI
- Class of the Month: Control Event Executions with the New Timer Class Gaylord MI
- Class of the Month: Control Event Executions with the New Timer Class Gladwin MI
- Class of the Month: Control Event Executions with the New Timer Class Grand Blanc MI
- Class of the Month: Control Event Executions with the New Timer Class Grand Haven MI
- Class of the Month: Control Event Executions with the New Timer Class Grand Ledge MI
- Class of the Month: Control Event Executions with the New Timer Class Grand Rapids MI
- Class of the Month: Control Event Executions with the New Timer Class Grandville MI
- Class of the Month: Control Event Executions with the New Timer Class Grosse Pointe MI
- Class of the Month: Control Event Executions with the New Timer Class Hamtramck MI
- Class of the Month: Control Event Executions with the New Timer Class Harper Woods MI
- Class of the Month: Control Event Executions with the New Timer Class Harrison Township MI
- Class of the Month: Control Event Executions with the New Timer Class Hazel Park MI
- Class of the Month: Control Event Executions with the New Timer Class Highland Park MI
- Class of the Month: Control Event Executions with the New Timer Class Hillsdale MI
- Class of the Month: Control Event Executions with the New Timer Class Holland MI
- Class of the Month: Control Event Executions with the New Timer Class Holly MI
- Class of the Month: Control Event Executions with the New Timer Class Holt MI
- Class of the Month: Control Event Executions with the New Timer Class Howell MI
- Class of the Month: Control Event Executions with the New Timer Class Hudsonville MI
- Class of the Month: Control Event Executions with the New Timer Class Inkster MI
- Class of the Month: Control Event Executions with the New Timer Class Ionia MI
- Class of the Month: Control Event Executions with the New Timer Class Jackson MI
- Class of the Month: Control Event Executions with the New Timer Class Jenison MI
- Class of the Month: Control Event Executions with the New Timer Class Kalamazoo MI
- Class of the Month: Control Event Executions with the New Timer Class Lake Orion MI
- Class of the Month: Control Event Executions with the New Timer Class Lansing MI
- Class of the Month: Control Event Executions with the New Timer Class Lapeer MI
- Class of the Month: Control Event Executions with the New Timer Class Lincoln Park MI
- Class of the Month: Control Event Executions with the New Timer Class Livonia MI
- Class of the Month: Control Event Executions with the New Timer Class Ludington MI
- Class of the Month: Control Event Executions with the New Timer Class Macomb MI
- Class of the Month: Control Event Executions with the New Timer Class Marquette MI
- Class of the Month: Control Event Executions with the New Timer Class Midland MI
- Class of the Month: Control Event Executions with the New Timer Class Monroe MI
- Class of the Month: Control Event Executions with the New Timer Class Mount Clemens MI
- Class of the Month: Control Event Executions with the New Timer Class Mount Morris MI
- Class of the Month: Control Event Executions with the New Timer Class Mount Pleasant MI
- Class of the Month: Control Event Executions with the New Timer Class Muskegon MI
- Class of the Month: Control Event Executions with the New Timer Class New Baltimore MI
- Class of the Month: Control Event Executions with the New Timer Class Niles MI
- Class of the Month: Control Event Executions with the New Timer Class Northville MI
- Class of the Month: Control Event Executions with the New Timer Class Novi MI
- Class of the Month: Control Event Executions with the New Timer Class Oak Park MI
- Class of the Month: Control Event Executions with the New Timer Class Okemos MI
- Class of the Month: Control Event Executions with the New Timer Class Owosso MI
- Class of the Month: Control Event Executions with the New Timer Class Petoskey MI
- Class of the Month: Control Event Executions with the New Timer Class Pinckney MI
- Class of the Month: Control Event Executions with the New Timer Class Plymouth MI
- Class of the Month: Control Event Executions with the New Timer Class Pontiac MI
- Class of the Month: Control Event Executions with the New Timer Class Port Huron MI
- Class of the Month: Control Event Executions with the New Timer Class Portage MI
- Class of the Month: Control Event Executions with the New Timer Class Redford MI
- Class of the Month: Control Event Executions with the New Timer Class Rochester MI
- Class of the Month: Control Event Executions with the New Timer Class Rockford MI
- Class of the Month: Control Event Executions with the New Timer Class Romulus MI
- Class of the Month: Control Event Executions with the New Timer Class Roseville MI
- Class of the Month: Control Event Executions with the New Timer Class Royal Oak MI
- Class of the Month: Control Event Executions with the New Timer Class Saginaw MI
- Class of the Month: Control Event Executions with the New Timer Class Saint Clair Shores MI
- Class of the Month: Control Event Executions with the New Timer Class Saint Johns MI
- Class of the Month: Control Event Executions with the New Timer Class Saline MI
- Class of the Month: Control Event Executions with the New Timer Class Sault Sainte Marie MI
- Class of the Month: Control Event Executions with the New Timer Class South Haven MI
- Class of the Month: Control Event Executions with the New Timer Class South Lyon MI
- Class of the Month: Control Event Executions with the New Timer Class Southfield MI
- Class of the Month: Control Event Executions with the New Timer Class Southgate MI
- Class of the Month: Control Event Executions with the New Timer Class Sterling Heights MI
- Class of the Month: Control Event Executions with the New Timer Class Sturgis MI
- Class of the Month: Control Event Executions with the New Timer Class Swartz Creek MI
- Class of the Month: Control Event Executions with the New Timer Class Taylor MI
- Class of the Month: Control Event Executions with the New Timer Class Temperance MI
- Class of the Month: Control Event Executions with the New Timer Class Three Rivers MI
- Class of the Month: Control Event Executions with the New Timer Class Traverse City MI
- Class of the Month: Control Event Executions with the New Timer Class Trenton MI
- Class of the Month: Control Event Executions with the New Timer Class Troy MI
- Class of the Month: Control Event Executions with the New Timer Class Utica MI
- Class of the Month: Control Event Executions with the New Timer Class Walled Lake MI
- Class of the Month: Control Event Executions with the New Timer Class Warren MI
- Class of the Month: Control Event Executions with the New Timer Class Waterford MI
- Class of the Month: Control Event Executions with the New Timer Class West Bloomfield MI
- Class of the Month: Control Event Executions with the New Timer Class Westland MI
- Class of the Month: Control Event Executions with the New Timer Class White Lake MI
- Class of the Month: Control Event Executions with the New Timer Class Wixom MI
- Class of the Month: Control Event Executions with the New Timer Class Wyandotte MI
- Class of the Month: Control Event Executions with the New Timer Class Wyoming MI
- Class of the Month: Control Event Executions with the New Timer Class Ypsilanti MI
- Class of the Month: Control Event Executions with the New Timer Class Zeeland MI
Related Local Event
Real-Time & Embedded Computing Conference-Detroit (RTECC)
Dates: 9/17/2009 - 9/17/2009
Location: Sterling Inn Banquet & Conference Center, Detroit
Sterling Heights, MI
View Details

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