I need to write a code for dispatcher

there three threads
thread work is to read a record from hast table .and after that it goes to sleep for 10 sec
after 10 sec it is free i.e idle state

when they are in idle state the dispatcher should know which thread is in sleep state assign a new thread
if u know it . i will be thankful to u