gnodet opened a new pull request, #20702:
URL: https://github.com/apache/camel/pull/20702

   ## Summary
   
   This PR introduces a new `ContextValue` abstraction that provides a unified 
API for thread-scoped data sharing, with implementations using either 
`ThreadLocal` (JDK 17+) or `ScopedValue` (JDK 25+ with virtual threads).
   
   ## Key Changes
   
   ### New ContextValue API
   - Add `ContextValue` interface in camel-util with factory methods for 
creating context values and executing operations within scoped contexts
   - Add `ContextValueFactory` with ThreadLocal implementation for base JDK
   - Add Java 25 multi-release JAR variant using `ScopedValue` when available 
and virtual threads are enabled
   
   ### API Improvements in ExtendedCamelContext
   - Add new scoped API methods with cleaner naming:
     - `setupRoutes(Runnable)` and `setupRoutes(Callable<T>)`
     - `createRoute(String, Runnable)` and `createRoute(String, Callable<T>)`
     - `createProcessor(String, Runnable)` and `createProcessor(String, 
Callable<T>)`
   - Deprecate the old boolean/void signaling methods (`setupRoutes(boolean)`, 
`createRoute(String)`, `createProcessor(String)`)
   
   ### Deprecations
   - Deprecate `NamedThreadLocal` in favor of `ContextValue.newThreadLocal()`
   
   ### Implementation Updates
   - Update `DefaultCamelContextExtension` to use `ContextValue.where()` for 
scoped execution
   - Update `DefaultReactiveExecutor` to use `ContextValue` instead of 
`NamedThreadLocal`
   - Simplify `Worker` class by removing cached `stats` field (now reads 
`statisticsEnabled` directly)
   
   ## Benefits
   
   The `ContextValue` abstraction allows Camel to leverage `ScopedValue` on JDK 
25+ when virtual threads are enabled, providing:
   - Better performance characteristics for virtual thread workloads (no 
pinning)
   - Immutable, inheritable values that work well with structured concurrency
   - Backward compatibility with `ThreadLocal` on older JDK versions
   
   ## Documentation
   
   Added documentation to `ContextValue` explaining that ThreadLocal variants 
should hold lightweight objects to avoid memory leaks with pooled threads.
   
   ---
   Pull Request opened by [Augment Code](https://www.augmentcode.com/) with 
guidance from the PR author


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to