Tick of timer

Hi. I need to implement a seconds counter to show the time it takes to perform a process. I have seen that this can be implemented with “poll request”, but I suspect that this may overload the server with “requests”, when there are several dozen clients connected. Is there a way to run a seconds counter on the client side and not on the server side?
I don’t need a plugin that shows a clock, but I think the best thing would be a solution that triggers a Listener every 1 second.
Thank you.

Hello. A (Vaadin) listener would have the same performance implications as polling, since the listener runs in server side, thus client-to-server communication is required in order to execute the listener. An efficient approach that doesn’t have this limitation is handling the timer exclusively in the client side.

Which version of the framework are you using? [Here]
(https://vaadin.com/directory/component/simple-timer-addon) there is an addon (for Vaadin 10+) based on that approach; unfortunately, it also does a lot of requests because of an [unrelated issue]
(https://github.com/FlowingCode/SimpleTimerAddon/issues/4), but that can be easily circumvented if you only need the timer for presentation purposes and don’t need to read its value in the server-side.

Thanks Javier, you have interpreted exactly what I need. The timer is for presentation purposes only and I don’t need to read its value on the server.
I am using Vaadin 14 LTS.
I tried the “Simple Timer Addon” component but it doesn’t have a “Listener” for every tick. :frowning:

While not available through the API, it’s possible to hook on the event that is fired at each tick:

timer.getElement().addEventListener("current-time-changed", ev->{
   System.out.println("tick");
});

As it is implemented now, there will be a lot of ticks per second, which could affect performance if several users are executing their timers at the same time. Would it be a reasonable trade-off if you were able to configure how often the tick occurs? I would like to know more about your use case, since it could be an interesting feature to add.

Thanks Javier.
I am working on a system that monitors the “runtime” of machines. Internally from Vaadin a Java API is consulted every 60 seconds to calculate data and update the view. In addition I implement MQTT so that the view updates changes at the same time that the changes occurred.
To give a better user experience, I want the clock that shows the “runtime” to increase every one second.
Do you think there is any difference if we implement it through setPollInterval ()?

Hi Diego, the timer can be configured to count up, and you could set a very large limit and set the current time to match the current runtime from the process, that way you won’t need to update it every second.

Leonardo Scardanzan:
Hi Diego, the timer can be configured to count up, and you could set a very large limit and set the current time to match the current runtime from the process, that way you won’t need to update it every second.

Sorry Leornardo, but I can’t see how that could solve my problema.
I need that update a Label with the current running time of a machine. This running time it is updated from a Rest API every minute, but visually I want to show each the seconds of minute increasing.