8000 named executors by fwbrasil · Pull Request #71 · mauricio/postgresql-async · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Dec 3, 2019. It is now read-only.

named executors #71

Merged
merged 1 commit into from
Dec 20, 2013
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@

package com.github.mauricio.async.db.util

import java.util.concurrent.{Executors, ThreadFactory}
import java.util.concurrent.{ Executors, ThreadFactory }
import java.util.concurrent.atomic.AtomicInteger

object DaemonThreadsFactory extends ThreadFactory {
def newThread(r: Runnable): Thread = {
case class DaemonThreadsFactory(name: String) extends ThreadFactory {

private val threadNumber = new AtomicInteger(1)

def newThread(r: Runnable): Thread = {
val thread = Executors.defaultThreadFactory().newThread(r)
thread.setDaemon(true)

return thread
val threadName = name + "-thread-" + threadNumber.getAndIncrement
thread.setName(threadName)
thread
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import java.util.concurrent.{ExecutorService, Executors}
import scala.concurrent.ExecutionContext

object ExecutorServiceUtils {
implicit val CachedThreadPool = Executors.newCachedThreadPool(DaemonThreadsFactory)
implicit val CachedThreadPool = Executors.newCachedThreadPool(DaemonThreadsFactory("db-async-default"))
implicit val CachedExecutionContext = ExecutionContext.fromExecutor( CachedThreadPool )

def newFixedPool( count : Int ) : ExecutorService = {
Executors.newFixedThreadPool( count, DaemonThreadsFactory )
def newFixedPool( count : Int, name: String ) : ExecutorService = {
Executors.newFixedThreadPool( count, DaemonThreadsFactory(name) )
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ import io.netty.util.internal.logging.{InternalLoggerFactory, Slf4JLoggerFactory
object NettyUtils {

InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory())
lazy val DefaultEventLoopGroup = new NioEventLoopGroup(0, DaemonThreadsFactory)
lazy val DefaultEventLoopGroup = new NioEventLoopGroup(0, DaemonThreadsFactory("db-async-netty"))

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import scala.concurrent.{ExecutionContextExecutorService, ExecutionContext}
object Worker {
val log = Log.get[Worker]

def apply() : Worker = apply(ExecutorServiceUtils.newFixedPool(1))
def apply() : Worker = apply(ExecutorServiceUtils.newFixedPool(1, "db-async-worker"))

def apply( executorService : ExecutorService ) : Worker = {
new Worker(ExecutionContext.fromExecutorService( executorService ))
Expand Down
0