为了账号安全,请及时绑定邮箱和手机立即绑定

Hadoop中Mapper类的setup函数在什么地方调用?

Hadoop中Mapper类的setup函数在什么地方调用?

慕田峪7331174 2018-11-28 15:11:57
Hadoop中Mapper类的setup函数在什么地方调用
查看完整描述

1 回答

?
慕姐8265434

TA贡献1813条经验 获得超2个赞

Hadoop中Mapper类的setup函数在什么地方调用
答:经过跟踪hadoop源码发现,Mapper类的setup()函数在Mapper类的run()函数中被调用。
向hadoop提交job后,hadoop会在MapTask的runNewMapper()或者runOldMapper()函数中使用反馈机制实例化具体的Mapper子类,然后调用这个对象的run()函数,其中setup()函数就在这个函数的开始被调用,因为hadoop会向setup()函数中传递Configuration等一些变量,所以我们可以通过重载setup()函数来获得系统变量实现自己的功能。
[java] view plaincopy
/**
* Expert users can override this method for more complete control over the
* execution of the Mapper.
* @param context
* @throws IOException
*/
public void run(Context context) throws IOException, InterruptedException {
setup(context);//只运行一次,可以重载实现自己的功能,比如获得Configuration中的参数
while (context.nextKeyValue()) {
map(context.getCurrentKey(), context.getCurrentValue(), context);
}
cleanup(context);



查看完整回答
反对 回复 2018-12-08
  • 1 回答
  • 0 关注
  • 947 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信