Updating image in Thread


I need to do a following thing:

On my init() method im loading an image into the Layout. Then after pressing a given button im starting few ScheduledExecutorServices for my backend operations. I have another executor in my MainUI that periodically, every second runs certain Runnable for me. This Runnable is obviously to update labels on screen, compute few other stuff and then display it, etc. etc.

Now im wondering if I could ask Vaadin to update the image I previously added into the layout. I already have the part where i generate image (it changes every second on my drive) but It seems I cannot really tell my Image to update itself on my screen…

This is how I declare my image (maybe this is wrong???)

resource = new FileResource(new File("***PATH***")); image = new Image("", resource); mainLayout.addComponent(image); Thanks in advance!

This should be possible. But you need to remember the following 1) You need to use Push for the UI to update 2) You need to use UI.access() with the Runnables (otherwise you get concurrent modification exception) 3) If you have background threads, remember to ensure that they end or clean them in SessionDestroyEvent, since Vaadin is not automatically removing background threads started by you.

Should I do both at the same time (push + access method) or just one of them at once is enough?

Yes, both. In normal cases push works automatically (just add @Push annotation). All UI updates outside main thread must be done via UI.access(…)