Stream Pool Size Optimization

In his famous concurrency book , Goetz suggests that the optimal number of threads in a pool can be calculated using

N threads = N CPU * U CPU * (1 + W/C) 

W/C is the ratio of expectation to calculation. I want to develop a custom Executor that will adjust the number of worker threads using ThreadPoolExecutor.setCorePoolSize() , but I don't know how to calculate the WC ratio. Assuming this ThreadPool is the only one used by my application, how can I calculate this ratio?

Is there a way to track how much time a workflow spends waiting / sleeping? Or is there an implementation for this problem?

+6
source share
1 answer

http://docs.oracle.com/javase/7/docs/api/java/lang/management/ThreadInfo.html

this class contains methods such as

getBlockedCount()

Returns the total number of times a thread associated with this ThreadInfo has been blocked from entering or re-entering the monitor.

getBlockedTime()

Returns the approximate accumulated elapsed time (in milliseconds) that the thread associated with this ThreadInfo blocked to enter or re-enter the monitor because thread conflict monitoring is enabled.

+1
source

Source: https://habr.com/ru/post/983752/


All Articles