-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix threadpool monitor when using virtual thread #1344
Conversation
Signed-off-by: JermaineHua <crazyhzm@apache.org>
WalkthroughThe changes made in the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (1)
sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/main/java/com/alipay/sofa/rpc/boot/container/ServerConfigContainer.java (1)
279-286
: Consider broader implications of thread pool executor type checkingWhile the changes to
startCustomThreadPoolMonitor
method improve compatibility with different thread implementations, it's worth considering the broader implications:
- Are there other places in the codebase that might benefit from similar type checking?
- Should we update the documentation or JavaDocs to reflect that custom thread pools may use executors other than
ThreadPoolExecutor
?- Is there a need for a more generic monitoring solution that can handle different types of executors?
Consider reviewing the entire codebase for similar patterns and potentially create a more generic solution for thread pool monitoring that can accommodate different executor types.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
- sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/main/java/com/alipay/sofa/rpc/boot/container/ServerConfigContainer.java (2 hunks)
|
||
Executor tmp = pool.getUserExecutor(); | ||
if (tmp instanceof ThreadPoolExecutor) { | ||
customThreadPoolMonitor.setThreadPoolExecutor((ThreadPoolExecutor) pool | ||
.getUserExecutor()); | ||
customThreadPoolMonitor.start(); | ||
poolNames.add(pool.getThreadPoolName()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Improve type checking and error handling for custom thread pool executors
The addition of the type check for ThreadPoolExecutor
is a good improvement for compatibility with different thread implementations, including virtual threads. However, there are a few suggestions to enhance this change:
- The indentation of the new code is inconsistent with the rest of the method. Please align it properly.
- Consider using a more descriptive variable name instead of
tmp
, such asexecutor
. - Add error handling or logging for cases where the executor is not a
ThreadPoolExecutor
.
Here's a suggested refactoring:
-
- Executor tmp = pool.getUserExecutor();
- if (tmp instanceof ThreadPoolExecutor) {
- customThreadPoolMonitor.setThreadPoolExecutor((ThreadPoolExecutor) pool
- .getUserExecutor());
- customThreadPoolMonitor.start();
- poolNames.add(pool.getThreadPoolName());
- }
+ Executor executor = pool.getUserExecutor();
+ if (executor instanceof ThreadPoolExecutor) {
+ customThreadPoolMonitor.setThreadPoolExecutor((ThreadPoolExecutor) executor);
+ customThreadPoolMonitor.start();
+ poolNames.add(pool.getThreadPoolName());
+ } else {
+ LOGGER.warn("Custom thread pool '{}' does not use ThreadPoolExecutor. Monitoring will be skipped.", pool.getThreadPoolName());
+ }
This refactoring improves code readability, maintains consistent indentation, and adds logging for cases where the executor is not a ThreadPoolExecutor
.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
Executor tmp = pool.getUserExecutor(); | |
if (tmp instanceof ThreadPoolExecutor) { | |
customThreadPoolMonitor.setThreadPoolExecutor((ThreadPoolExecutor) pool | |
.getUserExecutor()); | |
customThreadPoolMonitor.start(); | |
poolNames.add(pool.getThreadPoolName()); | |
} | |
Executor executor = pool.getUserExecutor(); | |
if (executor instanceof ThreadPoolExecutor) { | |
customThreadPoolMonitor.setThreadPoolExecutor((ThreadPoolExecutor) executor); | |
customThreadPoolMonitor.start(); | |
poolNames.add(pool.getThreadPoolName()); | |
} else { | |
LOGGER.warn("Custom thread pool '{}' does not use ThreadPoolExecutor. Monitoring will be skipped.", pool.getThreadPoolName()); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1344 +/- ##
============================================
- Coverage 83.01% 82.94% -0.08%
+ Complexity 2975 2973 -2
============================================
Files 340 340
Lines 9828 9831 +3
Branches 1176 1177 +1
============================================
- Hits 8159 8154 -5
- Misses 1157 1161 +4
- Partials 512 516 +4 ☔ View full report in Codecov by Sentry. |
Summary by CodeRabbit
ThreadPoolExecutor
instances are set in the custom thread pool monitor, reducing the risk of runtime errors.