<commit_before>[![Build Status][ci-img]][ci]
[![Coverage Status][coveralls-img]][coveralls]
[![Maven Version][maven-img]][maven]
[![Javadoc][javadoc-img]][javadoc]

# Context propagation library

Library to propagate `ThreadLocal` snapshots by reactivating in another thread.

Tools help automate propagation by capturing snapshots 
and ensuring proper closing of reactivated context snapshots:
- [`ContextAwareExecutorService`][ContextAwareExecutorService] that wraps any existing `ExecutorService`
- [`ContextAwareCompletableFuture`][ContextAwareCompletableFuture] that 
  propagates context snapshots into each successive `CompletionStage`.

## Terminology

### Context

A context contains a value. There is one _active_ context _per thread_.  
An `AbstractThreadLocalContext` base class is provided that allows nested contexts 
and provides predictable behaviour for out-of-order closing.

### ContextManager

Manages the active context.  
Can initialize a new context and provides to the active context.

### ContextSnapshot

A snapshot contains the current value from _all_ known context managers.  
These values can be _reactivated_ in another thread.  
Reactivated snapshots **must be closed** to avoid leaking context.  

All _context aware_ utility classes in this library are tested 
to make sure they reactivate _and_ close snapshots in a safe way.

## How to use this library

### Capturing a snapshot of ThreadLocal context values

Just before creating a new thread, capture a snapshot of all ThreadLocal context
values:<commit_msg>Update readme; fix typo<commit_after>[![Build Status][ci-img]][ci]
[![Coverage Status][coveralls-img]][coveralls]
[![Maven Version][maven-img]][maven]
[![Javadoc][javadoc-img]][javadoc]

# Context propagation library

Library to propagate `ThreadLocal` snapshots by reactivating in another thread.

Tools help automate propagation by capturing snapshots 
and ensuring proper closing of reactivated context snapshots:
- [`ContextAwareExecutorService`][ContextAwareExecutorService] that wraps any existing `ExecutorService`
- [`ContextAwareCompletableFuture`][ContextAwareCompletableFuture] that 
  propagates context snapshots into each successive `CompletionStage`.

## Terminology

### Context

A context contains a value. There is one _active_ context _per thread_.  
An `AbstractThreadLocalContext` base class is provided that allows nested contexts 
and provides predictable behaviour for out-of-order closing.

### ContextManager

Manages the active context.  
Can initialize a new context and provides access to the active context.

### ContextSnapshot

A snapshot contains the current value from _all_ known context managers.  
These values can be _reactivated_ in another thread.  
Reactivated snapshots **must be closed** to avoid leaking context.  

All _context aware_ utility classes in this library are tested 
to make sure they reactivate _and_ close snapshots in a safe way.

## How to use this library

### Capturing a snapshot of ThreadLocal context values

Just before creating a new thread, capture a snapshot of all ThreadLocal context
values:
{'fraction_non_alphanumeric': 0.06593760051463493, 'fraction_numerical': 0.0, 'mean_word_length': 5.659528907922912, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4842318', 'n_tokens_mistral': 818, 'n_tokens_neox': 779, 'n_words': 351}