8000 Merge pull request #71 from fwbrasil/master · mauricio/postgresql-async@d0c48f7 · 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.

Commit d0c48f7

Browse files
committed
Merge pull request #71 from fwbrasil/master
named executors
2 parents bd18edc + 80e054f commit d0c48f7

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

db-async-common/src/main/scala/com/github/mauricio/async/db/util/DaemonThreadsFactory.scala

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@
1616

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

19-
import java.util.concurrent.{Executors, ThreadFactory}
19+
import java.util.concurrent.{ Executors, ThreadFactory }
20+
import java.util.concurrent.atomic.AtomicInteger
2021

21-
object DaemonThreadsFactory extends ThreadFactory {
22-
def newThread(r: Runnable): Thread = {
22+
case class DaemonThreadsFactory(name: String) extends ThreadFactory {
23+
24+
private val threadNumber = new AtomicInteger(1)
2325

26+
def newThread(r: Runnable): Thread = {
2427
val thread = Executors.defaultThreadFactory().newThread(r)
2528
thread.setDaemon(true)
26-
27-
return thread
29+
val threadName = name + "-thread-" + threadNumber.getAndIncrement
30+
thread.setName(threadName)
31+
thread
2832
}
2933
}

db-async-common/src/main/scala/com/github/mauricio/async/db/util/ExecutorServiceUtils.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ import java.util.concurrent.{ExecutorService, Executors}
2020
import scala.concurrent.ExecutionContext
2121

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

26-
def newFixedPool( count : Int ) : ExecutorService = {
27-
Executors.newFixedThreadPool( count, DaemonThreadsFactory )
26+
def newFixedPool( count : Int, name: String ) : ExecutorService = {
27+
Executors.newFixedThreadPool( count, DaemonThreadsFactory(name) )
2828
}
2929

3030
}

db-async-common/src/main/scala/com/github/mauricio/async/db/util/NettyUtils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ import io.netty.util.internal.logging.{InternalLoggerFactory, Slf4JLoggerFactory
2121
object NettyUtils {
2222

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

2626
}

db-async-common/src/main/scala/com/github/mauricio/async/db/util/Worker.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import scala.concurrent.{ExecutionContextExecutorService, ExecutionContext}
2222
object Worker {
2323
val log = Log.get[Worker]
2424

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

2727
def apply( executorService : ExecutorService ) : Worker = {
2828
new Worker(ExecutionContext.fromExecutorService( executorService ))

0 commit comments

Comments
 (0)
0