Reputation: 339679
Is there some way to verify that code is executing on the user’s user interface thread (event loop thread)?
This question is the Vaadin equivalent of this question, Swing verify code on Event Dispatch Thread at runtime.
I know how to call UI::access
from a background thread to schedule a Runnable
to be run on the user-interface thread. My question is how to double-check that some executing code is indeed running on the user-interface thread.
I filed a feature request for this.
Upvotes: 0
Views: 188
Reputation: 8001
The framework is already full of asserts in various code paths that should only be run on the thread that has locked the UI state. The most important being whenever shared state is accessed.
To benefit from this checking, just make sure your server is run with assertion checking enabled, i.e. by starting it with the -ea
JVM parameter.
Upvotes: 1
Reputation: 1934
If UI.getCurrent()
returns an instance you are (most probably) either:
UI::access
To quote the Vaadin 7.3.9 doc:
… In other cases, (e.g. from background threads), the current UI is not automatically defined.
boolean uiOrUiAccessManagedThread = UI.getCurrent() != null;
Upvotes: 1