Home » Java » java – Spring Boot add property to new thread from Main on creation-Exceptionshub

java – Spring Boot add property to new thread from Main on creation-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

I have a spring boot webapp that receives a http request. I the make a number of further http calls in parallel on separate threads.
This is working fine, and I’ve implemented a custom Executor to configure my thread pool.

However, I have a property in the main thread that I want to make available on the other threads. This property is used in the headers of the downstream requests.
For example, the application has a library that calls ThreadContext.put(TRACKING_KEY, {{value}} at the start of every request it receives. At the minute I manually have to call ThreadContext.get(TRACKING_KEY) to get the value and pass it to the methods in my threaded calls and explicitly set it on each thread so it will be available further along the process.

My question is, is there an event or a listener that I can hook into that will allow me to get the property from the main thread and add it to the thread that’s being created

How to&Answers: