我有一个提交任务的固定线程池(仅限于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?
}
}
https://stackoverflow.com/questions/3294293
复制相似问题