Vaadin 8 Push is sometimes synchronous

225 views Asked by At

We have a Vaadin 8 application using @Push functionality to push data to the UI which should be loaded asynchronously.

To load the data, we create a Runnable which is executed in an Executor and then makes a callback to a function in the UI/View, where this code is called:

UI ui = getUI();
if (!isAttached() || ui.getSession().hasLock()) {
    MainViewComponentImpl.this.componentImpl.getSomeComponent().setVisible(true);
    MainViewComponentImpl.this.componentImpl.getSomeComponent().setItems(someHashMap.keySet());
} else {
    ui.access(new Runnable() {
        @Override
        public void run() {
            MainViewComponentImpl.this.componentImpl.getSomeComponent().setVisible(true);
            MainViewComponentImpl.this.componentImpl.getSomeComponent().setItems(someHashMap.keySet());
        }
    });
}

If the Runnable where the data is loaded has a Thread.sleep(TimeUnit.SECONDS.toMillis(15)) before doing the callback, then the data is actually pushed into the UI asynchronously, but if it is not, the UI hangs and loads it all together.

My first impression was, that the if/else checks wheather the UI is still being loaded, and if it can add the data to the current load, but even if we uncomment the if-clause and always use the ui.access() method, the data is loaded synchronously. Also, even with the Timeout, it is heavily build-dependent, wheather or not the data is actually loaded asynchronously. After a maven-update, clean project and maven build, most of the time it is asynchronously, but not always.

Is there anyone out there who experienced similar behaviour and made it work?

Thanks

0

There are 0 answers