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.
现在添加JVM参数
-Dsimbot.runInBlocking.dispatcher=virtual
即可将所有通过 BlockingRunner 执行的阻塞函数(xxxBlocking
)的调度器切换至虚拟线程。(你也可以在 #743 中通过
-Dsimbot.runInBlocking.dispatcher=custom
切换到其他自定义调度器 )不过需要注意的是,这里切换到的是
xxxBlocking
内的逻辑阻塞,而此函数本身则可能会被某个异步的虚拟线程 "join"。因此当开启BlockingRunner的虚拟线程调度器时,我们建议你将事件调度时使用的调度器也切换为虚拟线程。否则,在事件调度过程中仍会因物理线程被虚拟线程阻塞而导致影响效率。在普通的core模块应用中,你可以通过
ApplicationConfiguration
或SimpleListenerManagerConfiguration
的中的coroutineContext
来定制事件调度器。在
Spring Starter
中,向程序中注入一个CoroutineDispatcherContainer
的实例并使其携带一个虚拟线程的线程池。例如Java中: