views:

21

answers:

3

Hi,

i am trying to do an application,like if there are 10 separate tasks and 4 threads are running.My application has to maintain two queue one for tasks and another for threads.If any task needs to execute it should find which thread is free and assign the task to that thread.i dont know how to produce this.Anyone knows what are the concepts i have to look,please help me.

+1  A: 

It sounds like you just need a thread pool of the kind returned by Executors.newFixedThreadPool. Just submit the tasks to the thread pool when you need to, and it will be executed accordingly.

Jon Skeet
Beaten to the punch by The Skeet... by four seconds. Curse you, Jon! :)
Rytmis
A: 

I suppose you could make your tasks Runnable and use a ThreadPoolExecutor to run them.

Rytmis
+1  A: 

The ThreadPoolExecutor does pretty well exactly that for you.

Pete Kirkham