java - How-to provide a ThreadLocal to CompletableFutures? -


I need to provide ThreadLocal to all sources which are specific running futures SupplyAsync Supplier

I see from Javadock that the uses the integerful future " ForkJoinPool commonPool () " which is very my The display fits in the use case.

How do I transfer a threadlocal (and later delete) all the pool threads running a specific CompletableFuture supplier?

Note:

I suppose all the integerf async completion methods accept an executor. I would love to use the default ForkJoinPool commonPool () but if this is not possible, then I think I have to override Threadpool Explorer and implement the first code Execute ?

I think you have to find your way as if exec () On ForkJoinTask is protected You can of course write your cover for concrete implementation.

I will do this for a single threadlocal and for colable

  public static class withThreadLocal & lt; V, T & gt; Callable & lt; V> {Private Final Threadlock & lt; T & gt; ThreadLocal; Personal last t-value; Private Last Callable & lt; V> Repayable; Public withThreadLocal (Threadlocal & lt; t & gt; thread, local price, callable & lt; V & gt; callable) {this.threadLocal = threadLocal; This.value = value; this. Eligible = Callable; } @ Override Public V call () throws an exception {T oldValue = threadLocal.get (); Try {ThreadLocal.set (value); Return callable.call (); } Finally {threadLocal.set (oldValue); }}}  

From there you can use otherwise you can be interrupted in


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -