private boolean localizeAndLaunchTask ( final TaskInProgress tip ) throws IOException { FutureTask < Boolean > task = new FutureTask < Boolean > ( new Callable < Boolean > ( ) { public Boolean call ( ) throws IOException { JobConf localConf = localizeJob ( tip ) ; boolean launched = false ; synchronized ( tip ) { tip . setJobConf ( localConf ) ; launched = tip . launchTask ( ) ; } return launched ; } } ) ; String threadName = "Localizing " + tip . getTask ( ) . toString ( ) ; Thread thread = new Thread ( task ) ; thread . setName ( threadName ) ; thread . setDaemon ( true ) ; thread . start ( ) ; boolean launched = false ; try { launched = task . get ( LOCALIZE_TASK_TIMEOUT , TimeUnit . MILLISECONDS ) ; } catch ( Exception e ) { task . cancel ( true ) ; try { LOG . info ( "Wait the localizeTask thread to finish" ) ; thread . join ( LOCALIZE_TASK_TIMEOUT ) ; } catch ( InterruptedException ie ) { } if ( thread . isAlive ( ) ) { LOG . error ( "Stacktrace of " + threadName + "\n" + StringUtils . stackTraceOfThread ( thread ) ) ; LOG . fatal ( "Cannot kill the localizeTask thread." + threadName + " TaskTracker has to die!!" ) ; System . exit ( - 1 ) ; } throw new IOException ( "TaskTracker got stuck for localized Task:" + tip . getTask ( ) . getTaskID ( ) , e ) ; } return launched ; }
Localize and launch the task . If it takes too long try cancel the thread that does localization . If the thread cannot be terminated kill the JVM . The TaskTracker will die .