code: public int run(String[] args) throws Exception {
      if (args.length < 3) {
        System.out.println("Grep <inDir> <outDir> <regex> [<group>]");
        ToolRunner.printGenericCommandUsage(System.out);
        return -1;
      }
  
      Path tempDir =
        new Path("grep-temp-"+
            Integer.toString(new Random().nextInt(Integer.MAX_VALUE)));
  
      JobConf grepJob = new JobConf(getConf(), Grep.class);
      
      try {
        
        grepJob.setJobName("grep-search");
  
        FileInputFormat.setInputPaths(grepJob, args[0]);
  
        grepJob.setMapperClass(RegexMapper.class);
        grepJob.set("mapred.mapper.regex", args[2]);
        if (args.length == 4)
          grepJob.set("mapred.mapper.regex.group", args[3]);
  
        grepJob.setCombinerClass(LongSumReducer.class);
        grepJob.setReducerClass(LongSumReducer.class);
  
        FileOutputFormat.setOutputPath(grepJob, tempDir);
        grepJob.setOutputFormat(SequenceFileOutputFormat.class);
        grepJob.setOutputKeyClass(Text.class);
        grepJob.setOutputValueClass(LongWritable.class);
  
        JobClient.runJob(grepJob);
  
        JobConf sortJob = new JobConf(Grep.class);
        sortJob.setJobName("grep-sort");
  
        FileInputFormat.setInputPaths(sortJob, tempDir);
        sortJob.setInputFormat(SequenceFileInputFormat.class);
  
        sortJob.setMapperClass(InverseMapper.class);
  
        sortJob.setNumReduceTasks(1);                 // write a single file
        FileOutputFormat.setOutputPath(sortJob, new Path(args[1]));
        sortJob.setOutputKeyComparatorClass           // sort by decreasing freq
        (LongWritable.DecreasingComparator.class);
  
        JobClient.runJob(sortJob);
      }
      finally {
        FileSystem.get(grepJob).delete(tempDir, true);
      }
      return 0;
    }
docs: singleton