I created a timer "def" with interval 1000 (expected to be 1 sec). When expire, it system.out.println the current time. I also called the getTimeRemaining() inbetween to check the status of the timer. Here is the output:
schedule called at Mon Apr 06 17:55:43 CST 2009
def run 0 at Mon Apr 06 17:55:53 CST 2009
def run 1 at Mon Apr 06 17:56:00 CST 2009
Timer def will expire after 16 milliseconds.
Timer def will expire after 813 milliseconds.
Timer def will expire after 657 milliseconds.
Timer def will expire after 516 milliseconds.
def run 2 at Mon Apr 06 17:56:07 CST 2009
Timer def will expire after 1000 milliseconds.
Timer def will expire after 110 milliseconds.
def run 3 at Mon Apr 06 17:56:14 CST 2009
def run 4 at Mon Apr 06 17:56:21 CST 2009
def run 5 at Mon Apr 06 17:56:28 CST 2009
def run 6 at Mon Apr 06 17:56:35 CST 2009
Timer def will expire after 219 milliseconds.
Timer def will expire after 172 milliseconds.
Timer def will expire after 297 milliseconds.
def run 7 at Mon Apr 06 17:56:42 CST 2009
Timer def will expire after 360 milliseconds.
Timer def will expire after 313 milliseconds.
Timer def will expire after 422 milliseconds.
Timer def will expire after 782 milliseconds.
Timer def will expire after 500 milliseconds.
def run 8 at Mon Apr 06 17:56:49 CST 2009
Timer def will expire after 922 milliseconds.
Timer def will expire after 875 milliseconds.
Timer def will expire after 922 milliseconds.
Timer def will expire after 47 milliseconds.
def run 9 at Mon Apr 06 17:56:56 CST 2009
def cancelled
This is my createTimer statement:
timerService.createTimer(10000, 1000, "def");
The output tells the problem:
1. Why the time remaining went up and down inbetween 2 expiry?
2. Why the timer run every 7 sec instead of 1 sec?
[Message sent by forum member 'senderj' (senderj)]
http://forums.java.net/jive/thread.jspa?messageID=340869