Вопрос

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