Hadoop原始碼詳解之Job 類
阿新 • • 發佈:2018-12-27
Hadoop原始碼詳解之Job
類
1. 原始碼
- 包:
org.apache.hadoop.mapreduce
- 繼承的介面有:
AutoCloseable
,JobContext
,org.apache.hadoop.mapreduce.MRJobConfig
The job submitter’s view of the Job.
It allows the user to configure the job, submit it, control its execution, and query the state. The set methods only work until the job is submitted, afterwards they will throw an IllegalStateException.
Normally the user creates the application, describes various facets of the job via Job and then submits the job and monitor its progress.
作業提交者層次上的作業檢視。
它允許使用者配置job,提交它,並且控制它的執行,然後查詢狀態。set
方法 僅僅工作直到job被提交,否則會丟擲IllegalStateException
。
正常情況下,使用者建立一個應用,描述工作的各個方面,通過Job
類,並且提交job,然後監測它的進度。
下面給出一個示例關於如何使用 Job
類去提交一個job。
// Create a new Job
Job job = Job.getInstance();
job.setJarByClass(MyJob.class);
// Specify various job-specific parameters
job.setJobName("myjob");
job.setInputPath(new Path("in"));
job.setOutputPath(new Path("out"));
job.setMapperClass(MyJob.MyMapper.class);
job.setReducerClass(MyJob.MyReducer.class);
// Submit the job, then poll for progress until the job is complete
job. waitForCompletion(true);
2. 方法詳解
2.1 構造器
以前的構造器全部建議不再使用,轉而使用getInistance(...)
這個方法。
2.2 waitForCompletion
- 方法釋義
Submit the job to the cluster and wait for it to finish.
提交job到叢集,並且等待它完成。
- 方法原始碼
/**
* @param verbose print the progress to the user
* @return true if the job succeeded
* @throws IOException thrown if the communication with the JobTracker is lost
*/
public boolean waitForCompletion(boolean verbose
) throws IOException, InterruptedException,
ClassNotFoundException {
if (state == JobState.DEFINE) {
submit();
}
if (verbose) {
monitorAndPrintJob();
} else {
// get the completion poll interval from the client.
int completionPollIntervalMillis =
Job.getCompletionPollInterval(cluster.getConf());
while (!isComplete()) {
try {
Thread.sleep(completionPollIntervalMillis);
} catch (InterruptedException ie) {
}
}
}
return isSuccessful();
}