Binding
can be used. A block of code is said to be executing within a realm if calling {@link #isCurrent()} from that block returns true. Code reached by callingmethods from that block will execute within the same realm, with the exception of methods on this class that can be used to execute code within a specific realm. Clients can use {@link #syncExec(Runnable)}, {@link #asyncExec(Runnable)}, or {@link #exec(Runnable)} to execute arunnable within this realm. Note that using {@link #syncExec(Runnable)} canlead to deadlocks and should be avoided if the current thread holds any locks.
It is instructive to think about possible implementations of Realm: It can be based on executing on a designated thread such as a UI thread, or based on holding a lock. In the former case, calling syncExec on a realm that is not the current realm will execute the given runnable on a different thread (the designated thread). In the latter case, calling syncExec may execute the given runnable on the calling thread, but calling {@link #asyncExec(Runnable)} will execute the given runnable on a differentthread. Therefore, no assumptions can be made about the thread that will execute arguments to {@link #asyncExec(Runnable)}, {@link #syncExec(Runnable)}, or {@link #exec(Runnable)}.
It is possible that a block of code is executing within more than one realm. This can happen for implementations of Realm that are based on holding a lock but don't use a separate thread to run runnables given to {@link #syncExec(Runnable)}. Realm implementations of this kind should be appropriately documented because it increases the opportunity for deadlock.
Some implementations of {@link IObservable} provide constructors which do nottake a Realm argument and are specified to create the observable instance with the current default realm. The default realm can be set for the currently executing thread by using {@link #runWithDefault(Realm,Runnable)}. Note that the default realm does not have to be the current realm.
Subclasses must override at least one of asyncExec()/syncExec(). For realms based on a designated thread, it may be easier to implement asyncExec and keep the default implementation of syncExec. For realms based on holding a lock, it may be easier to implement syncExec and keep the default implementation of asyncExec.
@since 1.0 @see IObservable
|
|
|
|
|
|
|
|
|
|