public class LocalContext extends Context
This class represents a context to define locally scoped environment
settings. This settings are held by LocalContext.Reference
and typically wrapped within a static method:
LocalContext.enter();
try {
ModuloInteger.setModulus(m); // Performs integer operations modulo m.
Length.showAs(NonSI.INCH); // Shows length in inches.
RelativisticModel.select(); // Uses relativistic physical model.
... // Operations performed using local settings.
} finally {
LocalContext.exit(); // Reverts to previous settings.
}
Calls to locally scoped methods should be performed either at start-up (global setting) or within a local context (to avoid impacting other threads).
As for any context, local context settings are inherited during
concurrent
executions.
LocalMap
,
Serialized FormModifier and Type | Class and Description |
---|---|
static class |
LocalContext.Reference<T>
This class represents a reference whose setting is local to the current
LocalContext . |
Constructor and Description |
---|
LocalContext()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
static void |
enter()
Enters a
LocalContext possibly recycled. |
protected void |
enterAction()
The action to be performed after this context becomes the current
context.
|
static void |
exit()
Exits the current local context.
|
protected void |
exitAction()
The action to be performed before this context is no more the current
context.
|
enter, enter, exit, exit, getCurrentContext, getOuter, getOwner, setConcurrentContext, toString
public static void enter()
LocalContext
possibly recycled.public static void exit()
java.lang.ClassCastException
- if the context is not a local context.protected void enterAction()
Context
enterAction
in class Context
protected void exitAction()
Context
exitAction
in class Context
Copyright © 2005 - 2007 Javolution.