Class LocalContext
- java.lang.Object
-
- javolution37.javolution.realtime.Context
-
- javolution37.javolution.realtime.LocalContext
-
public class LocalContext extends Context
This class represents a local context; it is used to define locally scoped setting through the use of
LocalReferencetypically wrapped within a static method. For example:LocalContext.enter(); try { LargeInteger.setModulus(m); // Performs integer operations modulo m. Length.showAs(NonSI.INCH); // Shows length in inches. RelativisticModel.select(); // Uses relativistic physical model. QuantityFormat.getInstance(); // Returns local format for quantities. XmlFormat.setFormat(Foo.class, myFormat); // Uses myFormat for instances of Foo. } 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).
Finally, local settings are inherited by
concurrent threadsspawned while in a local context scope.- See Also:
LocalMap
-
-
Constructor Summary
Constructors Constructor and Description LocalContext()Default constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidclear()Removes all local settings for this context.static LocalContextcurrent()Returns the current local context ornullif the current thread does not execute within a local context (global context).static voidenter()Enters aLocalContext.static voidexit()Exits the currentLocalContext.
-
-
-
Method Detail
-
current
public static LocalContext current()
Returns the current local context ornullif the current thread does not execute within a local context (global context).- Returns:
- the current local context.
-
enter
public static void enter()
Enters aLocalContext.
-
exit
public static void exit()
Exits the currentLocalContext.- Throws:
java.lang.IllegalStateException- if the current context is not an instance of LocalContext.
-
-
DMelt 3.0 © DataMelt by jWork.ORG