Questions tagged «executors»

6
如何从线程池获取线程ID?
我有一个固定的线程池,我可以将任务提交给该线程池(限制为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? } }
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.