Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@aserrallerios
Created November 20, 2017 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aserrallerios/491f079d51eefff7753944190d8bfea6 to your computer and use it in GitHub Desktop.
Save aserrallerios/491f079d51eefff7753944190d8bfea6 to your computer and use it in GitHub Desktop.
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