Skip to content

Commit

Permalink
Merge pull request #931 from akka/wip-2.1-2778-thread-id-∂π
Browse files Browse the repository at this point in the history
 #2778 - make thread names unique per system (for 2.1)
  • Loading branch information
rkuhn committed Dec 8, 2012
2 parents 66efaa2 + e87e281 commit 302660c
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion akka-actor/src/main/scala/akka/actor/ActorSystem.scala
Expand Up @@ -616,7 +616,7 @@ private[akka] class ActorSystemImpl(val name: String, applicationConfig: Config,
protected def createScheduler(): Scheduler =
new DefaultScheduler(
new HashedWheelTimer(log,
threadFactory.copy(threadFactory.name + "-scheduler"),
threadFactory.withName(threadFactory.name + "-scheduler"),
settings.SchedulerTickDuration,
settings.SchedulerTicksPerWheel),
log)
Expand Down
Expand Up @@ -527,7 +527,7 @@ class ForkJoinExecutorConfigurator(config: Config, prerequisites: DispatcherPrer
val tf = threadFactory match {
case m: MonitorableThreadFactory
// add the dispatcher id to the thread names
m.copy(m.name + "-" + id)
m.withName(m.name + "-" + id)
case other other
}
new ForkJoinExecutorServiceFactory(
Expand Down
Expand Up @@ -20,7 +20,7 @@ class PinnedDispatcher(
_id: String,
_mailboxType: MailboxType,
_shutdownTimeout: FiniteDuration,
_threadPoolConfig: ThreadPoolConfig = ThreadPoolConfig())
_threadPoolConfig: ThreadPoolConfig)
extends Dispatcher(_prerequisites,
_id,
Int.MaxValue,
Expand Down
Expand Up @@ -92,7 +92,7 @@ case class ThreadPoolConfig(allowCorePoolTimeout: Boolean = ThreadPoolConfig.def
val tf = threadFactory match {
case m: MonitorableThreadFactory
// add the dispatcher id to the thread names
m.copy(m.name + "-" + id)
m.withName(m.name + "-" + id)
case other other
}
new ThreadPoolExecutorServiceFactory(tf)
Expand Down Expand Up @@ -183,9 +183,9 @@ object MonitorableThreadFactory {
case class MonitorableThreadFactory(name: String,
daemonic: Boolean,
contextClassLoader: Option[ClassLoader],
exceptionHandler: Thread.UncaughtExceptionHandler = MonitorableThreadFactory.doNothing)
exceptionHandler: Thread.UncaughtExceptionHandler = MonitorableThreadFactory.doNothing,
protected val counter: AtomicLong = new AtomicLong)
extends ThreadFactory with ForkJoinPool.ForkJoinWorkerThreadFactory {
protected val counter = new AtomicLong

def newThread(pool: ForkJoinPool): ForkJoinWorkerThread = {
val t = wire(new MonitorableThreadFactory.AkkaForkJoinWorkerThread(pool))
Expand All @@ -196,6 +196,8 @@ case class MonitorableThreadFactory(name: String,

def newThread(runnable: Runnable): Thread = wire(new Thread(runnable, name + "-" + counter.incrementAndGet()))

def withName(newName: String): MonitorableThreadFactory = copy(newName)

protected def wire[T <: Thread](t: T): T = {
t.setUncaughtExceptionHandler(exceptionHandler)
t.setDaemon(daemonic)
Expand Down
2 changes: 1 addition & 1 deletion akka-cluster/src/main/scala/akka/cluster/Cluster.scala
Expand Up @@ -95,7 +95,7 @@ class Cluster(val system: ExtendedActorSystem) extends Extension {
new DefaultScheduler(
new HashedWheelTimer(log,
system.threadFactory match {
case tf: MonitorableThreadFactory tf.copy(name = tf.name + "-cluster-scheduler")
case tf: MonitorableThreadFactory tf.withName(tf.name + "-cluster-scheduler")
case tf tf
},
SchedulerTickDuration,
Expand Down

0 comments on commit 302660c

Please sign in to comment.