配置 jOOQ 使用 Kotlin IO 调度程序

huangapple go评论49阅读模式
英文:

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() })
  )

huangapple
  • 本文由 发表于 2023年2月7日 04:59:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75366530.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定