Timer Trouble

I wrote a simple GUI to test/demo my Timer class that I had blogged about previously. In doing so, I discovered a bug in my implementation.

TimerDemo (Unsynchronized)
 Figure 1a: Unsynchronized timer in action

Figure 1a is a screenshot of the TimerDemo application that lets one configure the various attributes of the Timer class and test the timer by starting/stopping it. This TimerDemo application simply logs a couple of lines of text every time the timer action is invoked. The lines highlighted in grey show the timer action being invoked every 20 seconds.

TimerDemo (Synchronized)
Figure 1b: Synchronized timer in action

Figure 1b shows how the synchronized attribute of the Timer class affects when the first timer action is invoked. The highlighted portions in the above screenshot show that when a synchronized timer is used, the first invocation of the action occurs at the start of the next minute and thereafter when the configured interval expires.

The portion highlighted in yellow in Figure 1a shows a bug in my Timer implementation. It shows that the unsynchronized timer (incorrectly) invokes the action when the timer is started instead of after the expiry of the configured interval. The following diff fixes this bug:

--- Timer.fx.org    2008-05-31 23:52:40.000000000 +0530
+++ Timer.fx    2008-05-31 23:51:01.000000000 +0530
@@ -105,7 +105,6 @@
             };
             sync.start();
         } else {
-            alarm();
             tick.start();
         }
     }

And now my Timer works better!

TimerDemo (post bugfix)

Attachments:

  1. TimerDemo.zip (consolidated source files)

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

arvindsrinivasan

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today