Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion core/jvm/src/main/scala/zio/internal/DefaultExecutors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ import java.util.concurrent.{RejectedExecutionException, ThreadPoolExecutor}
private[zio] abstract class DefaultExecutors {

final def makeDefault(): zio.Executor =
new ZScheduler
makeDefault(true)

final def makeDefault(autoBlocking: Boolean): zio.Executor =
new ZScheduler(autoBlocking)

final def fromThreadPoolExecutor(
es: ThreadPoolExecutor
Expand Down
12 changes: 7 additions & 5 deletions core/jvm/src/main/scala/zio/internal/ZScheduler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import java.util.concurrent.locks.LockSupport
* applications. Inspired by "Making the Tokio Scheduler 10X Faster" by Carl
* Lerche. [[https://tokio.rs/blog/2019-10-scheduler]]
*/
private final class ZScheduler extends Executor {
private final class ZScheduler(autoBlocking: Boolean) extends Executor {
private[this] val poolSize = java.lang.Runtime.getRuntime.availableProcessors
private[this] val cache = MutableConcurrentQueue.unbounded[ZScheduler.Worker]
private[this] val globalQueue = MutableConcurrentQueue.unbounded[Runnable]
Expand All @@ -47,10 +47,12 @@ private final class ZScheduler extends Executor {
}
workers.foreach(_.start())

private[this] val supervisor = makeSupervisor()
supervisor.setName("ZScheduler-Supervisor")
supervisor.setDaemon(true)
supervisor.start()
if (autoBlocking) {
val supervisor = makeSupervisor()
supervisor.setName("ZScheduler-Supervisor")
supervisor.setDaemon(true)
supervisor.start()
}

def metrics(implicit unsafe: Unsafe): Option[ExecutionMetrics] = {
val metrics = new ExecutionMetrics {
Expand Down