英文:
Configuring jOOQ to use the Kotlin IO dispatcher
问题
jOOQ中的默认执行器默认使用ForkJoinPool common pool,或者在只有一个CPU可用时使用未经管理的普通线程:
由于我使用标准的阻塞式JDBC驱动程序(而不是像r2dbc这样的异步驱动程序),大多数情况下,jOOQ线程的时间将花在等待I/O上,因此建议分配比ForkJoinPool
common pool提供的线程更多,后者的默认大小似乎更适合CPU密集型工作。
我正在使用Kotlin协程,应该如何将jOOQ的执行器与我的Kotlin Dispatchers.IO
线程池集成,后者具有更好的默认线程配置,适用于执行阻塞I/O操作?
英文:
The default executor in jOOQ uses the ForkJoinPool common pool by default, or plain unmanaged threads when only one CPU is available:
Since I use a standard blocking JDBC driver (as opposed to an async driver like r2dbc), most of the time jOOQ threads spend will be waiting for I/O, it is advisable to allocate more threads than provided by the ForkJoinPool
common pool, the default sizes of which seem to be configured more for CPU-intensive work.
I'm using Kotlin coroutines, what would the best way be to integrate jOOQ's executor with my Kotlin Dispatchers.IO
thread pool, which has a better default configuration for threads doing blocking IO?
答案1
得分: 1
使用Kotlin,可以使用asExecutor()
扩展函数将IO调度程序作为执行器获取。因此,配置jOOQ以使用它非常简单:
DSL
.using(
DefaultConfiguration()
.set(ExecutorProvider { Dispatchers.IO.asExecutor() })
)
英文:
With Kotlin, the IO dispatcher can be obtained as an executor using the asExecutor()
extension function. Therefore, configuring jOOQ to use it is simple:
DSL
.using(
DefaultConfiguration()
.set(ExecutorProvider { Dispatchers.IO.asExecutor() })
)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论