Contexts are created and used to manage the execution
environment. They provide a convenient location for
storing globals organized by the module using the
globals.
A basic context implementation is provided as an abstract
class; this implementation satisfies the interface and
should in general be used as the supertype of all context
types. Otherwise, context classes must satisfy the
semantics of the interface through their own distinct
implementations.
Contexts assist in cleanup
when errors are caught in the outer block.
Use of context cleanup is preferred over using try/catch
blocks throughout the code.
Use of context pushing and popping is preferred over
using many instance or local variables, even when try/catch is present.
when the instance or local variables would be holding resources.
Usually Context's have a reference based equality, ie. they do not provide
an implementation of equals(). Contexts may implement a value based equality
but this usually means there is only one instance of the Context on the stack,
This is because the popContext(Context) will remove the most recently pushed
Context that matches via the equals method, not by a reference check.
Implementing equals is useful for Contexts used in notifyAllThreads() that
is not aimed at a single thread.
|