@@ -21,7 +21,7 @@ import java.io._
2121import java .net .{InetAddress , Inet4Address , NetworkInterface , URI , URL , URLConnection }
2222import java .nio .ByteBuffer
2323import java .util .{Locale , Random , UUID }
24- import java .util .concurrent .{ConcurrentHashMap , Executors , ThreadPoolExecutor }
24+ import java .util .concurrent .{ThreadFactory , ConcurrentHashMap , Executors , ThreadPoolExecutor }
2525
2626import scala .collection .JavaConversions ._
2727import scala .collection .Map
@@ -553,30 +553,37 @@ private[spark] object Utils extends Logging {
553553 new ThreadFactoryBuilder ().setDaemon(true )
554554
555555 /**
556- * Wrapper over newCachedThreadPool. Thread names are formatted as prefix-ID, where ID is a
557- * unique, sequentially assigned integer.
556+ * Create a thread factory that names threads with a prefix and also sets the threads to daemon.
558557 */
559- def newDaemonCachedThreadPool (prefix : String ): ThreadPoolExecutor = {
560- val threadFactory = daemonThreadFactoryBuilder.setNameFormat(prefix + " -%d" ).build()
561- Executors .newCachedThreadPool(threadFactory).asInstanceOf [ThreadPoolExecutor ]
558+ def namedThreadFactory (prefix : String ): ThreadFactory = {
559+ daemonThreadFactoryBuilder.setNameFormat(prefix + " -%d" ).build()
562560 }
563561
564562 /**
565- * Return the string to tell how long has passed in milliseconds.
563+ * Wrapper over newCachedThreadPool. Thread names are formatted as prefix-ID, where ID is a
564+ * unique, sequentially assigned integer.
566565 */
567- def getUsedTimeMs (startTimeMs : Long ): String = {
568- " " + (System .currentTimeMillis - startTimeMs) + " ms"
566+ def newDaemonCachedThreadPool (prefix : String ): ThreadPoolExecutor = {
567+ val threadFactory = namedThreadFactory(prefix)
568+ Executors .newCachedThreadPool(threadFactory).asInstanceOf [ThreadPoolExecutor ]
569569 }
570570
571571 /**
572572 * Wrapper over newFixedThreadPool. Thread names are formatted as prefix-ID, where ID is a
573573 * unique, sequentially assigned integer.
574574 */
575575 def newDaemonFixedThreadPool (nThreads : Int , prefix : String ): ThreadPoolExecutor = {
576- val threadFactory = daemonThreadFactoryBuilder.setNameFormat (prefix + " -%d " ).build( )
576+ val threadFactory = namedThreadFactory (prefix)
577577 Executors .newFixedThreadPool(nThreads, threadFactory).asInstanceOf [ThreadPoolExecutor ]
578578 }
579579
580+ /**
581+ * Return the string to tell how long has passed in milliseconds.
582+ */
583+ def getUsedTimeMs (startTimeMs : Long ): String = {
584+ " " + (System .currentTimeMillis - startTimeMs) + " ms"
585+ }
586+
580587 private def listFilesSafely (file : File ): Seq [File ] = {
581588 val files = file.listFiles()
582589 if (files == null ) {
0 commit comments