Results 1 to 5 of 5
Thread: Timer
- 06-07-2010, 03:28 PM #1
Member
- Join Date
- Nov 2008
- Posts
- 4
- Rep Power
- 0
Timer
Hi All,
I have a program in java which is running already for some time... It is used for logging variables from a PLC. The program is running on Win XP.
For some PLC items I use timers to log them periodically.
Snippets from the code
import java.util.Timer;
import java.util.TimerTask;
public class blabla {........
static Timer timerT10s;
upon initialisation
if (grpT10s != null) {
if (timerT10s != null) {
timerT10s.cancel();
}
Timer timerT10s = new Timer ( ) ;
timerT10s.scheduleAtFixedRate ( new TimerTaskT10s ( ), 250 ,10000 ) ;
}
and timertask
class TimerTaskT10s extends TimerTask {
public void run ( ) {
.....
}
All works quite ok.
Now we found that whenever we change the clock in win XP problems start happening with the timers.
(A) If I set the clock one hour later, I see the application is hogging the CPU up to 100% cpu load.
(B) If I change the clock to one hour earlier, the CPU load is 0% for the application and if I set a breakpoint in my timertaskT10S, there is no stop on the breakpoint.
It looks to me that in situation (A) the timers will callback faster and in situation (B) the timers not callback at all.
I have searched for this, but cannot find information on it.
Is this a common problem with the timers in Java ?
Can something be done about it ? (and yes I must be able to change the clock)
Any suggestions are welcome
- 06-08-2010, 01:11 AM #2
Senior Member
- Join Date
- Mar 2010
- Posts
- 266
- Rep Power
- 4
perhaps don't use Timer? make your own thread that would look like
while(true) {
Thread.sleep(aWhile);
doStuff();
}
- 06-08-2010, 06:34 AM #3
Member
- Join Date
- Nov 2008
- Posts
- 4
- Rep Power
- 0
For the longer timers I can imagine that it works. However I also have timers 10ms and 100ms and they are short for a purpose. It is why I use executeAtFixedRate.... a sleep I think will never be accurate
- 06-08-2010, 06:40 AM #4
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
As far as I know, the Java timer classes are based on Thread.sleep... so it will most likely not make much of a difference.
If the above doesn't make sense to you, ignore it, but remember it - might be useful!
And if you just randomly taught yourself to program, well... you're just like me!
- 06-08-2010, 06:17 PM #5
Senior Member
- Join Date
- Mar 2010
- Posts
- 266
- Rep Power
- 4
Similar Threads
-
Need help with timer
By firecat318 in forum New To JavaReplies: 6Last Post: 05-31-2010, 02:38 AM -
Timer help
By Kinyo in forum New To JavaReplies: 15Last Post: 03-15-2009, 02:37 AM -
EJB Timer
By mrjunsy in forum Advanced JavaReplies: 0Last Post: 08-22-2008, 04:09 PM -
EJB Timer
By mrjunsy in forum New To JavaReplies: 0Last Post: 08-04-2008, 06:47 PM -
How to cancel an individual timer in spite of canceling whole timer
By Java Tip in forum java.utilReplies: 0Last Post: 04-04-2008, 02:46 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks