Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Display indeterminate ProgressBar during heavy computation logic execution

Shaun Thomas
5 years ago Nov 29, 2016 11:29am

I want to show an indeterminate ProgressBar on click of a checkbox in OptionGroup to prevent user interaction until some heavy computation task is performed. I followed the logic specified in https://vaadin.com/docs/-/part/framework/components/components-progressbar.html. On the valueChange listener of the checkbox I run a thread. The body of the run method of the thread is as follows.

getMyComponent().getUI().access(new Runnable() {
  @Override public void run() {

// Some heavy computation logic


Here showWaitIndicator() method displays the ProgressBar and hideWaitIndicator() method hides it. When I run the code, it happens that sometimes the showWaitIndicator() is executed only after the heavy computation logic and hideWaitIndicator() method are executed resulting in ProgressBar displayed forever. How can I make sure that the logic in the code shown above is executed only in the expected order.

Note: I posted the same question in stackoverflow yesterday - http://stackoverflow.com/questions/40853582/vaadin-send-response-from-heavy-computation-logic but didn't get any satisfied answer.

Leif Åstrand
5 years ago Nov 29, 2016 1:07pm

You also need to use a Runnable and UI.access for hideWaitInidicator(). Runnables passed to UI.access are (sometimes) run asynchronously, but they are guaranteed to be run in a consistent order (technically, they are immediately added to a threadsafe queue, and that queue is then asynchronously purged).

Another thing to look out for is to make sure you have enabled push for the UI or that you're using use UI.setPollInterval. Without either of those, it might be that hideWaitIndicator() is actually run after showWaitIndicator(), but the browser never sends any message to the server that would make it discover that the progress bar has been removed.