Created
November 20, 2017 08:43
-
-
Save aserrallerios/491f079d51eefff7753944190d8bfea6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.ThreadFactory | |
import java.util.concurrent.atomic.AtomicInteger | |
class DefaultThreadFactory(name: String) extends ThreadFactory { | |
final private val group = Thread.currentThread.getThreadGroup | |
final private val threadNumber = new AtomicInteger(1) | |
final private def threadName = s"pool-$name-thread-${threadNumber.getAndIncrement}" | |
def newThread(r: Runnable): Thread = { | |
val t = new Thread(group, r, threadName, 0) | |
if (t.isDaemon) t.setDaemon(false) | |
if (t.getPriority != Thread.NORM_PRIORITY) t.setPriority(Thread.NORM_PRIORITY) | |
t | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment