最佳答案
我有一个固定的线程池,我提交任务(限于 5线程)。如何找出哪个 5线程执行我的任务(类似于“ 5的线程 # 3正在执行此任务”) ?
ExecutorService taskExecutor = Executors.newFixedThreadPool(5);
//in infinite loop:
taskExecutor.execute(new MyTask());
....
private class MyTask implements Runnable {
public void run() {
logger.debug("Thread # XXX is doing this task");//how to get thread id?
}
}