5252
5353public class TezThreadDumpHelper {
5454
55- private final long duration ;
55+ private final long threadDumpFrequency ;
56+ private final long threadDumpInitialDelay ;
5657 private final Path basePath ;
5758 private final FileSystem fs ;
5859
5960 private static final ThreadMXBean THREAD_BEAN = ManagementFactory .getThreadMXBean ();
6061 private static final Logger LOG = LoggerFactory .getLogger (TezThreadDumpHelper .class );
61- private final long initialDelay ;
6262
6363 private ScheduledExecutorService periodicThreadDumpServiceExecutor ;
6464
65- private TezThreadDumpHelper (long duration , long initialDelay , Configuration conf ) throws IOException {
66- this .duration = duration ;
67- this .initialDelay = initialDelay ;
65+ private TezThreadDumpHelper (long threadDumpFrequency , long threadDumpInitialDelay , Configuration conf )
66+ throws IOException {
67+ this .threadDumpFrequency = threadDumpFrequency ;
68+ this .threadDumpInitialDelay = threadDumpInitialDelay ;
6869 Appender appender = org .apache .log4j .Logger .getRootLogger ().getAppender (TezConstants .TEZ_CONTAINER_LOGGER_NAME );
6970 if (appender instanceof TezContainerLogAppender ) {
7071 this .basePath = new Path (((TezContainerLogAppender ) appender ).getContainerLogDir ());
@@ -75,19 +76,20 @@ private TezThreadDumpHelper(long duration, long initialDelay, Configuration conf
7576 this .fs = this .basePath .getFileSystem (conf );
7677 }
7778 LOG .info ("Periodic Thread Dump Capture Service Configured to capture Thread Dumps at {} ms frequency and at "
78- + "path: {} with an initial delay of {}" , duration , basePath , initialDelay );
79+ + "path: {} with an initial delay of {}" , threadDumpFrequency , basePath , threadDumpInitialDelay );
7980 }
8081
8182 public static TezThreadDumpHelper getInstance (Configuration conf ) {
82- long periodicThreadDumpFrequency = conf .getTimeDuration (TEZ_THREAD_DUMP_INTERVAL ,
83- TEZ_THREAD_DUMP_INTERVAL_DEFAULT , TimeUnit .MILLISECONDS );
84- Preconditions .checkArgument (periodicThreadDumpFrequency > 0 , "%s must be positive duration" ,
85- TEZ_THREAD_DUMP_INTERVAL );
86- long initialDelay = conf .getTimeDuration (TEZ_THREAD_DUMP_INITIAL_DELAY , TEZ_THREAD_DUMP_INITIAL_DELAY_DEFAULT ,
87- TimeUnit .MILLISECONDS );
83+ long threadDumpFrequency =
84+ conf .getTimeDuration (TEZ_THREAD_DUMP_INTERVAL , TEZ_THREAD_DUMP_INTERVAL_DEFAULT , TimeUnit .MILLISECONDS );
85+ Preconditions .checkArgument (threadDumpFrequency > 0 , "%s must be positive duration" , TEZ_THREAD_DUMP_INTERVAL );
86+ long threadDumpInitialDelay =
87+ conf .getTimeDuration (TEZ_THREAD_DUMP_INITIAL_DELAY , TEZ_THREAD_DUMP_INITIAL_DELAY_DEFAULT ,
88+ TimeUnit .MILLISECONDS );
89+ Preconditions .checkArgument (threadDumpInitialDelay >= 0 , "%s can not be negative" , TEZ_THREAD_DUMP_INITIAL_DELAY );
8890
8991 try {
90- return new TezThreadDumpHelper (periodicThreadDumpFrequency , initialDelay , conf );
92+ return new TezThreadDumpHelper (threadDumpFrequency , threadDumpInitialDelay , conf );
9193 } catch (IOException e ) {
9294 throw new TezUncheckedException ("Can not initialize periodic thread dump service" , e );
9395 }
@@ -98,8 +100,8 @@ public TezThreadDumpHelper start(String name) {
98100 new ThreadFactoryBuilder ().setDaemon (true ).setNameFormat ("PeriodicThreadDumpService{" + name + "} #%d" )
99101 .build ());
100102 Runnable threadDumpCollector = new ThreadDumpCollector (basePath , name , fs );
101- periodicThreadDumpServiceExecutor .scheduleWithFixedDelay (threadDumpCollector , initialDelay , duration ,
102- TimeUnit .MILLISECONDS );
103+ periodicThreadDumpServiceExecutor .scheduleWithFixedDelay (threadDumpCollector , threadDumpInitialDelay ,
104+ threadDumpFrequency , TimeUnit .MILLISECONDS );
103105 return this ;
104106 }
105107
0 commit comments