我付出之后
JobClient.runJob(jobConf)
如何获取此MapReduce任务的JobID?
我在下面看过如下代码,但它会返回所有当前正在运行的作业ID
System.out.println("Printing job IDs...");
JobClient client = new JobClient(jobConf);
JobStatus[] status = client.getAllJobs();
for(int i = 0; i < status.length; i++){
if(!status[i].isJobComplete()){
JobID jobid = status[i].getJobID();
System.out.println(jobid.toString());
}
}
更新
好的,我忽略了一些事情。 runJob
方法返回RunningJob
对象,该对象具有getID
方法。但RunningJob
对象仅在作业完成运行后返回。无论如何在工作仍在运行时获取ID?
RunningJob currentJob = JobClient.runJob(jobConf);
System.out.println("JobID: " + currentJob.getID().toString());
答案 0 :(得分:1)
SubmitJob似乎可以解决问题。
JobClient client = new JobClient(jobConf);
RunningJob currentJob = client.submitJob(jobConf);
System.out.println("JobID: " + currentJob.getID().toString());
答案 1 :(得分:0)
要获取作业ID的值,在作业运行时,您可以在新API中使用以下代码,
int value = job.waitForCompletion(true)? 0:1;
JobID jobId = job.getJobID();
//使用jobId的逻辑
返回值;