I am using an Executor with 4 threads.
Executor exec = Executors.newFixedThreadPool(this.numOfThreads);
Runnable requestHandler = new Runnable() {
@Override
public void run() {
try {
getImageForURL(spURL, 0);
} catch (IOException ex) {
} catch (Exception ex) {
}
}
};
exec.execute(requestHandler);
In getImageForURL, I am printing the name of the thread and the output looks like this. The output does not look right, or is this how it is suppose to look?
name=pool-1-thread-1
name=pool-2-thread-1
name=pool-3-thread-1
name=pool-4-thread-1
name=pool-5-thread-1
name=pool-6-thread-1
name=pool-7-thread-1
name=pool-8-thread-1
name=pool-9-thread-1
name=pool-10-thread-1
name=pool-11-thread-1
name=pool-12-thread-1
name=pool-13-thread-1
name=pool-14-thread-1
You are creating a new pool every time (by repeatedly calling
newFixedThreadPool). You probably want to create the pool just once (when you start your program), and submit multiplerequestHandlerto it.The output should then look something like:
with the thread number going up to 4 if the pool is fully utilized.