Skip to content
This repository has been archived by the owner on Sep 18, 2021. It is now read-only.

Commit

Permalink
Ensure all our threadpools are setup correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Raghavendra Prabhu committed Mar 14, 2012
1 parent 0179a0d commit 40e0e2d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
Expand Up @@ -3,12 +3,12 @@ package com.twitter.querulous
import java.util.concurrent.ThreadFactory
import java.util.concurrent.atomic.AtomicInteger

class DaemonThreadFactory extends ThreadFactory {
val group = new ThreadGroup(Thread.currentThread().getThreadGroup(), "querulous")
class DaemonThreadFactory(nameSuffix : String) extends ThreadFactory {
val group = new ThreadGroup(Thread.currentThread().getThreadGroup(), "querulous-" + nameSuffix)
val threadNumber = new AtomicInteger(1)

def newThread(r: Runnable) = {
val thread = new Thread(group, r, "querulous-" + threadNumber.getAndIncrement())
val thread = new Thread(group, r, "querulous-" + nameSuffix + "-" + threadNumber.getAndIncrement())
if (!thread.isDaemon) {
thread.setDaemon(true)
}
Expand Down
Expand Up @@ -12,7 +12,7 @@ class FutureTimeout(poolSize: Int, queueSize: Int) {
60,
TimeUnit.SECONDS,
new LinkedBlockingQueue[Runnable](queueSize),
new DaemonThreadFactory()
new DaemonThreadFactory("futureTimeout")
)

class Task[T](f: => T)(onTimeout: T => Unit) extends Callable[T] {
Expand Down
Expand Up @@ -12,7 +12,7 @@ import com.twitter.conversions.time._


object AsyncQueryEvaluator extends AsyncQueryEvaluatorFactory {
lazy val defaultWorkPool = FuturePool(Executors.newCachedThreadPool(new DaemonThreadFactory))
lazy val defaultWorkPool = FuturePool(Executors.newCachedThreadPool(new DaemonThreadFactory("asyncWorkPool")))
lazy val defaultMaxWaiters = Int.MaxValue

def checkoutPool(maxWaiters: Int) = {
Expand All @@ -22,7 +22,8 @@ object AsyncQueryEvaluator extends AsyncQueryEvaluatorFactory {
1, /* max size */
0, /* ignored, since the sizes are the same */
TimeUnit.MILLISECONDS, /* similarly ignored */
new LinkedBlockingQueue(maxWaiters)))
new LinkedBlockingQueue[Runnable](maxWaiters),
new DaemonThreadFactory("asyncCheckoutPool")))
}

private def createEvaluatorFactory() = {
Expand Down

0 comments on commit 40e0e2d

Please sign in to comment.