Removing MonitorableThread
This commit is contained in:
parent
ea150eff61
commit
5fd515d16c
1 changed files with 6 additions and 26 deletions
|
|
@ -145,39 +145,19 @@ case class ThreadPoolConfigDispatcherBuilder(dispatcherFactory: (ThreadPoolConfi
|
|||
|
||||
class MonitorableThreadFactory(val name: String, val daemonic: Boolean = false) extends ThreadFactory {
|
||||
protected val counter = new AtomicLong
|
||||
protected val doNothing: Thread.UncaughtExceptionHandler =
|
||||
new Thread.UncaughtExceptionHandler() {
|
||||
def uncaughtException(thread: Thread, cause: Throwable) = {}
|
||||
}
|
||||
|
||||
def newThread(runnable: Runnable) = {
|
||||
val t = new MonitorableThread(runnable, name)
|
||||
val t = new Thread(runnable, name + counter.incrementAndGet())
|
||||
t.setUncaughtExceptionHandler(doNothing)
|
||||
t.setDaemon(daemonic)
|
||||
t
|
||||
}
|
||||
}
|
||||
|
||||
object MonitorableThread {
|
||||
val DEFAULT_NAME = "MonitorableThread".intern
|
||||
|
||||
// FIXME use MonitorableThread.created and MonitorableThread.alive in monitoring
|
||||
val created = new AtomicInteger
|
||||
val alive = new AtomicInteger
|
||||
}
|
||||
|
||||
class MonitorableThread(runnable: Runnable, name: String)
|
||||
extends Thread(runnable, name + "-" + MonitorableThread.created.incrementAndGet) {
|
||||
|
||||
setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
|
||||
def uncaughtException(thread: Thread, cause: Throwable) = {}
|
||||
})
|
||||
|
||||
override def run = {
|
||||
try {
|
||||
MonitorableThread.alive.incrementAndGet
|
||||
super.run
|
||||
} finally {
|
||||
MonitorableThread.alive.decrementAndGet
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* As the name says
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue