I am not a java expert, and my question is somewhat abstract, i need an advice on how is a best to implement my suggested architecture and requirements.
I will describe my requirements:
I have a manager object that receives tasks to process (holds a a task queue), the manager should distribute tasks between dedicated threads. each thread knows to execute only specific type of tasks.
I created a Main Manager class with a collection of type specific threads,
When a Main manager receives a new task it will push a task to the queue of a thread class object that knows how to handle this task (each thread has it’s own task queue).
A thread need to pool a task from his queue when he finished to handle previous task, but if the queue is empty , he should not use resources and need to be awaken when a new task arrives.
My though (may be not so good) was to use threads that extend timer object and with a timed task of checking its queue, but this does not fit to my requirement to free resources until a new task arrives.
Any suggestion of the best way to handle those system requirement will be appreciated (My Question is not a homework but rather a part of my developing tasks).
EDIT
(An answer to @Alexander Torstling) I am using currently a Blocking Queue as a tasks queue, my question is not a concurrency issue but rather an architectural , i want to free resources when the queue is empty and i want to be awaken maybe by event if a new task arrives, if i have finished handling with a task and i have more of them i will continue to handle next task;
Have a look at BlockingQueue. And in order to avoid creating too many threads, you might want to consider using an Executor, which can manage a thread pool for you.