Domanda

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?

È stato utile?

Soluzione

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.

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top