0

我准备好了一份 MR 工作。./bin/hadoop jar jarname到目前为止,我一直在通过调用来运行任务。

现在我必须从另一个 java 进程运行相同的 MR 作业。我该怎么做?

谢谢。

4

1 回答 1

3

如果您确实想hadoop jar从外部 java 程序运行,您可以尝试 ProcessBuilder。

 ProcessBuilder probuilder = new ProcessBuilder("hadoop jar...");
 // Start the process and wait for it to finish. 
 Process process = processBuilder.start();

 //Read output
 InputStream is = process.getInputStream();
 InputStreamReader ir = new InputStreamReader(is);
 BufferedReader br = new BufferedReader(ir);
 String line;
  while ((line = br.readLine()) != null) {
        System.out.println(line);
 }

 int exitStatus = process.waitFor();
 System.out.println("Job finished with status: " + exitStatus);
于 2013-09-26T16:24:15.810 回答