I would like to make use of the servlet async api. Therefore I need to offload work to other threads while keeping state of the thread the work was offloaded from. For spring security there is DelegatingSecurityContextExecutor that could be leverages. However there are more cases in data services where thread local state is kept. How can I make sure that all this state is transferred to the other thread? I know of micrometer-context-propagation that can be used for such tasks. But is this supported by data services? I haven’t found something in the A12 docs regarding this topic.
The reason I would like to offload work is that the application I am working on has an expensive request that might get cancelled when still being processed. In order to reduce server load I would like to stop processing for cancelled requests. This can be achieved by making use of the servlet async api.
As far as I am aware of, Data Services does not integrate micrometer-context-propagation. There is no ContextRegistry/ThreadLocalAccessor setup anywhere in the Data Services code base — the only Micrometer dependency that ships is micrometer-registry-prometheus for metrics. Even with context-propagation on the classpath it would only carry state for which a ThreadLocalAccessor is registered; A12 registers none, so its own thread-local state will not be transferred.
The thread-local state I am aware of:
-
Spring Security context. Configured as SecurityContextHolder.MODE_INHERITABLETHREADLOCAL (in DataServicesCoreAutoconfiguration). Note: inheritable thread-local only helps threads you spawn directly, not a pooled Executor — that is the case DelegatingSecurityContextExecutor is meant for.
-
A12 operation context (com.mgmtp.a12.dataservices.utils.OperationContextHolder) — operation id, per-operation context map, error flag. Set up and cleared by JsonRpcOperationDispatcher per RPC batch, used only for intra-batch SpEL chaining. Self-contained if you offload a whole dispatch; lost if you split one dispatch across threads.
-
LoadedDocumentReferencesContextHolder (internal) — request-scoped, used for attachment thumbnail URLs.
-
Standard Spring/SLF4J state — RequestContextHolder and the logging MDC. Not A12-specific.
These are the contexts I am aware of — there may be more, and there is no public API to snapshot and re-attach the complete set of A12 thread locals across threads.