Technical Article: Experimenting with Java Timers

OTN's new tech article is "Experimenting with Java Timers" by T. Lamine Ba. This article studies time—how Java handles timers and the scheduling of tasks. Java timers are utilities that let you execute threads or tasks at a predetermined future time, and these tasks can be repeated according to a set frequency.

The article starts with a simple "Hello World" program in a web application that's composed of JavaServer Pages (JSP) and uses the model-control-view (MVC) design pattern. The IDE used in this article is NetBeans IDE 7.1, but you can use any IDE that supports Java.

"Experimenting with Java Timers" demonstrates how to get started scheduling jobs with Java. To learn about Swing timers, check out the Java tutorial "How to Use Swing Timers" and additional information in the Java Platform, Standard Edition 7 API Specification for Class Timer

Comments:

Unfortunately, that article is flawed.

The class diagram claims that MyTask "is a" (i. e. extends) MyTimer, as does the description to Listing 2: "MyTask is a subclass of MyTimer, and it inherits all of its attributes, which allows for the manipulation of the object display."

However, in Listing 2 MyTask is a subclass of java.util.TimerTask, and a private _inner class_ (!) of MyTimer. That is how it gains access to MyTimers members.

Since beginners might read this, accuracy in such things should be important.

Posted by Flexx on June 11, 2014 at 10:26 AM PDT #

Indeed, this is a mistake. MyTask is an inner class of MyTimer instead.

Posted by guest on June 25, 2014 at 01:15 PM PDT #

Thanks for you feedback. We've corrected the article (and the image in the blog).

Posted by Tori on July 09, 2014 at 07:58 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Insider News from the Java Team at Oracle!

duke
Links


Search

Archives
« May 2015
SunMonTueWedThuFriSat
     
1
2
3
4
9
10
11
15
16
17
21
22
23
24
25
26
27
28
29
30
31
      
Today