I’ve just started looking at Java’s Executors class and the newCachedThreadPool( ) method. According to the API, the resulting thread pool reuses existing Thread objects for new tasks.
I’m a bit puzzled how this is implemented because I couldn’t find any method in the Thread API that lets you set the behaviour of an existing Thread object.
For example, you can create a new Thread from a Runnable object, which makes the Thread call the Runnable‘s run( ) method. However, there is no setter method in the Thread API that takes a Runnable as an argument.
I’d appreciate any pointers.
Executors does everything for you in the background. And yes it uses the existing thread API only.
Below link has sample implementation of Thread pool implemented using Thread class and Collection API: http://www.ibm.com/developerworks/library/j-jtp0730/index.html