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?

有帮助吗?

解决方案

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.

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top