Getting the UI in case of callback into a Vaadin application - IllegalState

I am writing a Vaadin Flow application that spins off a discrete-event simulation. The simulation framework runs the simulation model in a separate thread. The simulation allows me to schedule events that do a callback at certain moments in the future.

I would like to use this mechanism to progress a Vaadin ProgressBar in the View that coordinates running the simulation. This will allow the user to see progress as the simulation runs.

When the callback is executed, I am getting an IllegalStateException - “Cannot access state in VaadinSession or UI without locking the session.”, see the stacktrace below.

When trying UI.getCurrent().getSession().lock();, I get a NPE, since UI.getCurrent() returns null.

Could anyone tell me what my options for getting the correct UI object…? Thanks.

Caused by: java.lang.IllegalStateException: Cannot access state in VaadinSession or UI without locking the session.
    at com.vaadin.flow.server.VaadinSession.checkHasLock(
    at com.vaadin.flow.server.VaadinSession.checkHasLock(
    at com.vaadin.flow.internal.StateTree.checkHasLock(
    at com.vaadin.flow.internal.StateTree.markAsDirty(
    at com.vaadin.flow.internal.StateNode.markAsDirty(
    at com.vaadin.flow.internal.nodefeature.NodeMap.setChanged(
    at com.vaadin.flow.internal.nodefeature.NodeMap.put(
    at com.vaadin.flow.internal.nodefeature.ElementPropertyMap.putWithDeferredChangeEvent(
    at com.vaadin.flow.internal.nodefeature.ElementPropertyMap.put(
    at com.vaadin.flow.internal.nodefeature.AbstractPropertyMap.setProperty(
    at com.vaadin.flow.internal.nodefeature.ElementPropertyMap.setProperty(
    at com.vaadin.flow.dom.impl.BasicElementStateProvider.setProperty(
    at com.vaadin.flow.dom.Element.setRawProperty(
    at com.vaadin.flow.dom.Element.setProperty(
    at com.vaadin.flow.component.progressbar.GeneratedVaadinProgressBar.setValue(

Here’s one example:

Yes, that seems to be just what I need. Many thanks for your prompt response.