【发布时间】:2019-08-06 21:22:08
【问题描述】:
我想在MyThreadPoolExecutor 中覆盖ThreadPoolExecutor 中的protected void beforeExecute(Thread t, Runnable r) { },我想知道哪个线程提交了这个(t)线程要运行的任务?我想将任务提交线程的 threadLocals 复制到要运行此任务的线程(t)(在 threadPool 中)。
【问题讨论】:
-
在任何设计中,通常线程执行线程并不关心提交它的线程是什么,但如果你真的想要它,你可以在提交时将线程id保存在任务中。
标签: java multithreading threadpool executorservice thread-local