If you want only certain threads to execute certain tasks you a standard Threadpool will not fit. But you can use multiple Threadpools with only one thread in each to solve your problem.
Queues for every thread in thread pool
-
30-05-2022 - |
質問
As far I know, thread pools (java.util.concurrent.Executor class) provide a queue of tasks for all threads in a pool. So I don't really know, which thread will execute my task. But I need to have queues of tasks assigned to every thread. How can I do it?
解決
他のヒント
You should write your program so you don't need to know what thread executes a task. They are just anonymous worker threads.
However, if you really want to know anyway you can create a single threaded ExecutorService for each thread you want and then you will know which thread will execute a task.
所属していません StackOverflow