Provides exclusive access to this session from outside a request handling thread.
The given runnable is executed while holding the session lock to ensure exclusive access to this session. If this session is not locked, the lock will be acquired and the runnable is run right away. If this session is currently locked, the runnable will be run before that lock is released.
RPC handlers for components inside this session do not need to use this method as the session is automatically locked by the framework during RPC handling.
Please note that the runnable might be invoked on a different thread or later on the current thread, which means that custom thread locals might not have the expected values when the runnable is executed. Inheritable values in {@link CurrentInstance} will have the same values as when thismethod was invoked. {@link VaadinSession#getCurrent()} and{@link VaadinService#getCurrent()} are set according to this sessionbefore executing the runnable. Non-inheritable CurrentInstance values including {@link VaadinService#getCurrentRequest()} and{@link VaadinService#getCurrentResponse()} will not be defined.
The returned future can be used to check for task completion and to cancel the task. To help avoiding deadlocks, {@link Future#get()} throwsan exception if it is detected that the current thread holds the lock for some other session.
@see #lock()
@see #getCurrent()
@see #accessSynchronously(Runnable)
@see UI#access(Runnable)
@since 7.1
@param runnable the runnable which accesses the session
@return a future that can be used to check for task completion and tocancel the task