Reputation: 3497
I want to have a timer task that runs two tasks with fixed delays between each task.
For example:
A------B-----A------B
0------10----20----30
I tried using this code:
timer.scheduleAtFixedRate(taskA, 0, 10000);
timer.scheduleAtFixedRate(taskB, 10000, 10000);
but that gives me:
A-----A,B-----A,B
0-----10------20
How do I do this using Timer and TimerTask?
Upvotes: 0
Views: 201
Reputation: 5326
Just double your interval:
timer.scheduleAtFixedRate(taskA, 0, 20000);
timer.scheduleAtFixedRate(taskB, 10000, 20000);
Upvotes: 2
Reputation: 234795
I would do this with a single Task that maintains an internal toggle.
Upvotes: 1
Reputation: 23629
Create one Timer and have it alternate the the task it calls. Or create two Timers that one for Task A and one for Task B that have double the delay.
Upvotes: 1