dushkin
dushkin

Reputation: 2101

Java Executors Service for a fixed pool

I have an application which might use hundreds or even thousands of threads simultaneously, for a fixed period of time each.

What should be size of thread pool? - Is there a rule of thumb formula for this number. I understood using the number of processors is an advisable number. Is it the maximum number to set?

Upvotes: 0

Views: 54

Answers (1)

fg78nc
fg78nc

Reputation: 5232

For CPU bound tasks it should be number of processors.

int N = Runtime.getRuntime().availableProcessors();

For I/O bound tasks it can be more than number of processors , because some of threads may not be utilized during I/O intensive tasks. You should estimate ratio of wait time for your average I/O request. Once you get this ratio RT, you can use formula N*(1+RT), where N is number of processors.

Upvotes: 1

Related Questions