Framework for administration, get, set, save, restore, thread switching, formatting and logging thread local variables.The main class for the administration of the thread local variables is
IvyThreadContext. This class provides static methods to:
- create new thread local variables
- get all thread local variables
- get a specific thread local variable
- get the value of a specific thread local variable
- format the value of a specific thread local variable
- save all thread local variables to a memento
- restore the variables of all thread local variables from a memento
- get the value of a specific thread local varable from a memento
- format the value of a specific thread local variable from a memento
- dump all values of all thread local variables
IIvyThreadLocaland one to store values in a stack (
IIvyThreadLocalStack. Both classes are generics so that the type of the value can be specified.
All thread local variables can be used to log thread context information if using Log4J and the Layout class
IvyLog4jLayout. f a thread local variable is included by default in the logged thread context information can be specified when the thread local variable is created. However the
IvyLog4jLayoutclass can be configured to include any thread local variable available into the thread context.
Thread context printing is fine but in most of the cases the thread context is not interesting at the time an exception is catched / logged. More interesting is the thread context at the time the exception is thrown. To support this use case there exists two Exception classes
IvyRuntimeException. These classes are saving the whole ivy thread context (all thread local variables) during the creation of the exception. The Layout
IvyLog4jLayoutwill recognise these exceptions and will also log the thread context of the exceptions and there causes and there causes and so on. This allows a much better analyses of errors.
The format of a thread local variable in the log can be influenced by specifying a implementation of the
IIvyThreadLocalFormatterinterface during the creation of the variable.
Class Summary Class Description IvyAsyncRunnerRuns async code in the Ivy context which was active while the runner was created.
This allows the execution of code that runs against the ivy API in a any thread pool.