Hi,
This is for Vert.x 2 (we haven't upgraded to 3 yet). If I have a verticle, and do this:
public class WannaWork extends Verticle {
public void start(final Future<Void> startedResult) {
vertx.setTimer(initialDelay, oneShotTimerHandler -> {
workWorkWork();
vertx.setPeriodic(refreshInterval, periodicTimerHandler -> workWorkWork());
});
then will workWorkWork() run in the Vert.x event loop in a single threaded thread safe manner, like other requests to the verticle via the event loop?
Or will it run in a parallel multi threaded manner so that there will be concurrency problems if workWorkWork() modifies member fields?
Can I for example inside workWorkWork() safely do, say, this:
Map newMap = ...
this.someMap.retainAll(newMap);
this.someMap.put(...);
this.whatever = "something else";
(nothing here is thread safe)
?
Or would this result in concurrency bugs & undefined behavior?
I had a look at the docs:
-- but they don't say anything about where the timer callback runs (inside Vert.x loop or in "any" "random" thread). Didn't find anything in this forum either.
We actually have a verticle that calls setPeriodic, which triggers a computation that takes fairly long — but whilst this computation is running, the verticle is still able to reply to requests on the event loop (!) which makes me think the setTimer & setPeriodic callbacks don't run in the same verticle in a single threaded manner.
Best regards,
KajMagnus