Friday, July 8, 2011

Executing java programs in thread pool

Recently, i came across with the requirement of executing a java process in a thread pool. Below is the code listing. There are two versions of the program. One is to create the maximum number of threads at the outset and when the number of requests exceed the maximum number of threads, create new threads. The newly created threads process the request and will be destroyed at the end. Whereas the threads created during start up will be put back into the stack. The other version is to never create a new thread and queue the requests until a thread is available.