Scheduling tasks with Eclipse Vert.x

cescoffier
240 views

Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content

Cancelling timers

To cancel a timer (one-shot or periodic), call cancelTimer specifying the timer id:

Cancelling a timer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package io.vertx.playground;
import io.vertx.core.Vertx;
public class CancellationExample {
private static int counter = 0;
public static void main(String... args) {
Vertx vertx = Vertx.vertx();
long timerId = vertx.setPeriodic(1000, id -> {
System.out.println("Hello " + ++counter);
if (counter == 2) {
System.out.println("Cancelling task");
vertx.cancelTimer(id);
}
});
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content