คำถามติดแท็ก executors

6
จะรับ id เธรดจากเธรดพูลได้อย่างไร
ฉันมีกลุ่มเธรดคงที่ที่ฉันส่งงานให้ (จำกัด5เธรด) ฉันจะทราบได้อย่างไรว่าเธรดหนึ่งใน5เธรดใดดำเนินการกับงานของฉัน (เช่น "เธรด # 3 จาก5กำลังทำงานนี้") 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? } }
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.