How to trigger UI updates from other threads?

My application (under development) in the background asynchronously communicates with a bunch of other systems and based on the results of that communication it should update corresponding fields in the UI.

Now I ran into an issue that when another thread tries to update the UI I am getting the following exception:

Exception refreshing UI
java.lang.IllegalStateException: Cannot access state in VaadinSession or UI without locking the session.
	at com.vaadin.flow.server.VaadinSession.checkHasLock(

I have to say that this didn’t come totally unexpected, because practically all UI frameworks I have worked with so far know some restrictions as to which thread(s) may handle and update the UI.

My question thus: Can each thread just grab and lock that session mentioned in the error message (if so: how?) or what else is the suggested/best approach or pattern to inform some UI element (in my case a Grid or TreeGrid bound to a couple of beans using a binder) that some value of one of the beans it visualizes has changed and that it thus should update the bean’s visualization? How should another thread trigger such an update without running into the above issue?

I didn’t find anything re. this subject in the vaadin doc’s but maybe I just didn’t come up with the right search terms. Any pointer would be appreciated!

Can each thread just grab and lock that session mentioned in the error message

Simple answer is, sort of yes. The magic keyword here is ui.access(..) method. Other important keywords are Push and asynchronous updates of the ui. This story is fully explained in this training video. The training video is accompanied with exercise project.

Excellent! Worked like a charm!
Thanks for the pointer to the trainings.