Hadoop程序中Configured类的用法是什么? [英] What is the usage of Configured class in Hadoop programs
问题描述
public class MyApp extends Configured Implements Tool {
@Override
public int run(String [] args)throws Exception {
Job job = new Job(getConf());
/ *进程命令行选项* /
return job.waitForCompletion(true)? 0:1;
public static void main(String [] args)throws Exception {
int exitCode = ToolRunner.run(new MyApp(),args);
System.exit(exitCode);
$ b $ p $ 的用法是什么?配置
?作为工具
和已配置
都有 getConf()
和 setConf()
共同。它为我们的应用程序提供了什么?解决方案 Configured
类可配置
。 Configured
是具有 getConf()
和 setConf()
。
仅仅扩展这个基类使得扩展它的类可以使用 Configuration
并且 Configuration
有多个实现。
当您的代码执行以下行时,
ToolRunner.run (新的MyApp(),args);
内部会执行此操作
<$ p $ ToolRunner.run(tool.getConf(),tool,args);
在上面的例子中, tool
code> MyApp 类实例,它是工具
的一个实现,就像你说的 getConf()
但它只是一个界面。该实现来自 Configured
基类。如果您避免在上面的代码中扩展 Configured
类,那么您将必须执行 getConf()
和 setConf()
自己实现。
Most of Hadoop MapReduce programs are like this:
public class MyApp extends Configured Implements Tool {
@Override
public int run(String[] args) throws Exception {
Job job = new Job(getConf());
/* process command line options */
return job.waitForCompletion(true) ? 0 : 1;
}
public static void main(String[] args) throws Exception {
int exitCode = ToolRunner.run(new MyApp(), args);
System.exit(exitCode);
}
}
What is the usage of Configured
? As Tool
and Configured
both have getConf()
and setConf()
in common. What does it provide to our application?
Configured
is an implementation class of Configurable
. Configured
is the base class which has the implementations of getConf()
and setConf()
.
Merely extending this base class enables the class that extends this to be configured using a Configuration
and there are more than one implementations for Configuration
.
When your code executes the following line,
ToolRunner.run(new MyApp(), args);
Internally it will do this
ToolRunner.run(tool.getConf(), tool, args);
In the above case tool
is the MyApp
class instance which is an implementation of Tool
which just as you said has getConf()
but it is just as an interface. The implementation is coming from Configured
base class. If you avoid extending Configured
class in the above code, then you will have to do the getConf()
and setConf()
implementations on your own.
这篇关于Hadoop程序中Configured类的用法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!