{{ message }}
WIP: ThreadWorkerPool支持newVirtualThreadPerTaskExecutor方式使用虚拟线程#71
Merged
wardseptember merged 7 commits intoJan 9, 2025
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #71 +/- ##
=====================================================
- Coverage 70.13750% 70.10816% -0.02935%
- Complexity 4212 4238 +26
=====================================================
Files 434 437 +3
Lines 17018 17105 +87
Branches 1726 1727 +1
=====================================================
+ Hits 11936 11992 +56
- Misses 3969 3996 +27
- Partials 1113 1117 +4
|
Contributor
Author
|
I have read the CLA Document and I hereby sign the CLA |
| .getDeclaredMethod(NEW_THREAD_PER_TASK_EXECUTOR_NAME, ThreadFactory.class); | ||
| ThreadPerTaskExecutorWrapper wrappedThreadPool = ThreadPerTaskExecutorWrapper | ||
| .wrap((ExecutorService) newThreadPerTaskExecutorMethod.invoke(executorsClazz, threadFactory)); | ||
| threadPool = wrappedThreadPool; |
Collaborator
There was a problem hiding this comment.
这一行看起来多余,threadPool没有地方使用
Contributor
Author
There was a problem hiding this comment.
这个threadPool变量是ThreadWorkPool的属性,是线程池的实例,会有跟维护ThreadWorkPool生命周期相关的操作
| ThreadPerTaskExecutorWrapper wrappedThreadPool = ThreadPerTaskExecutorWrapper | ||
| .wrap((ExecutorService) newThreadPerTaskExecutorMethod.invoke(executorsClazz, threadFactory)); | ||
| threadPool = wrappedThreadPool; | ||
| threadPoolMXBean = new ThreadPerTaskExecutorMXBeanImpl(wrappedThreadPool); |
Contributor
Author
There was a problem hiding this comment.
这里代码覆盖需要跑在Java21或者支持fiber的KonaJDK上
| @@ -0,0 +1,30 @@ | |||
| package com.tencent.trpc.core.management; | |||
|
|
|||
| import javax.management.MalformedObjectNameException; | |||
| return useThreadPerTaskExecutor; | ||
| } | ||
|
|
||
| public void setUseThreadPerTaskExecutor(boolean useThreadPerTaskThread) { |
Collaborator
There was a problem hiding this comment.
useThreadPerTaskThread命名是不是错了,useThreadPerTaskExecutor
| ThreadPerTaskExecutorWrapper wrappedThreadPool = ThreadPerTaskExecutorWrapper | ||
| .wrap((ExecutorService) newThreadPerTaskExecutorMethod.invoke(executorsClazz, threadFactory)); | ||
| threadPool = wrappedThreadPool; | ||
| threadPoolMXBean = new ThreadPerTaskExecutorMXBeanImpl(wrappedThreadPool); |
Collaborator
There was a problem hiding this comment.
threadPool 和threadPoolMXBean 会被覆盖掉
| package com.tencent.trpc.core.management; | ||
|
|
||
| /* | ||
| * Tencent is pleased to support the open source community by making tRPC available. |
liuzengh
added a commit
to liuzengh/cla-database
that referenced
this pull request
Jul 21, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

用Executors.newVirtualThreadPerTaskExecutor()的方式使用虚拟线程,用ThreadPerTaskExecutor代替,用完立即销毁
使用ExecutorServiceWrapper去实现ThreadPoolMXBean临时使用反射实现,只简单统计了提交和完成的任务数量,近似替代相关数据监控。JEP#444建议使用JFR来监控虚拟线程。