Skip to content

Commit

Permalink
Ensure jobs are closed to prevent threadleak in invoking java process
Browse files Browse the repository at this point in the history
  • Loading branch information
Asger Askov Blekinge committed Nov 24, 2021
1 parent 9ea5aef commit bf63986
Showing 1 changed file with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,27 @@ public int run(String[] args) throws InterruptedException, IOException, ClassNot
Path inputPath = new Path(args[0]);
Path outputPath = new Path(args[1]);
Configuration conf = getConf();
Job job = Job.getInstance(conf);
job.setJobName("HadoopJob using " + mapper.getClass().getSimpleName());

//job.setJarByClass(this.getClass());
job.setInputFormatClass(NLineInputFormat.class);
job.setOutputFormatClass(TextOutputFormat.class);
NLineInputFormat.addInputPath(job, inputPath);
TextOutputFormat.setOutputPath(job, outputPath);
job.setMapperClass(mapper.getClass());
job.setNumReduceTasks(0); // Ensure job is map-only

// How many files should each node process at a time (how many lines are read from the input file)
NLineInputFormat.setNumLinesPerSplit(job, 5);

// In- and output types
job.setMapOutputKeyClass(NullWritable.class);
job.setMapOutputValueClass(Text.class);
job.setOutputKeyClass(NullWritable.class);
job.setOutputValueClass(Text.class);

return job.waitForCompletion(true) ? 0 : 1;
try (Job job = Job.getInstance(conf)) {
job.setJobName("HadoopJob using " + mapper.getClass().getSimpleName());

//job.setJarByClass(this.getClass());
job.setInputFormatClass(NLineInputFormat.class);
job.setOutputFormatClass(TextOutputFormat.class);
NLineInputFormat.addInputPath(job, inputPath);
TextOutputFormat.setOutputPath(job, outputPath);
job.setMapperClass(mapper.getClass());
job.setNumReduceTasks(0); // Ensure job is map-only

// How many files should each node process at a time (how many lines are read from the input file)
NLineInputFormat.setNumLinesPerSplit(job, 5);

// In- and output types
job.setMapOutputKeyClass(NullWritable.class);
job.setMapOutputValueClass(Text.class);
job.setOutputKeyClass(NullWritable.class);
job.setOutputValueClass(Text.class);

return job.waitForCompletion(true) ? 0 : 1;
}
}
}

0 comments on commit bf63986

Please sign in to comment.