Is screen controller thread safe?

Hello,

I am wondering about whether it’s safe to store an object in the screen controller, is it safe to do the following for example:

public class IncrementValueWindow extends AbstractWindow {
    @Inject
    TextField field;

    Integer x = 0;

    public void onIncrementX(Component source){
        x++;
    }

    public void onShowX(Component source){
        field.setValue(x.toString());
    }
}

Hi,

All the UI code is executed in a single-request-per-session mode. Once HTTP request is handled it obtains a special lock on the HTTP session and releases it after response is sent to client. It guarantees that all your screens / buttons / etc is updated correctly. It means that you can safely update any field / UI component / datasource from event handlers of UI components and UI actions.

It does not mean though that you can run multiple threads and update any UI thing in parallel, use BackgroundTasks for such background threads not bound to UI event handling.

1 Like