今天在论坛上看见一个函数cleanup。查了下API。发现Mapper和Reducer都实现了这个函数。
描述:cleanup
protected void cleanup(Mapper.Context context)
throws IOException,
InterruptedExceptionCalled once at the end of the task.
Throws:
IOException
InterruptedException
论坛上的那个人来这个函数来统计总的词频数:
public void cleanup(Context context) throws IOException,
InterruptedException {
context.write(new Text("sum"), new IntWritable(sum));
}
这个用法不错,记上一笔。
在查看cleanuo函数的同时,还有一个类似的函数:
setup
protected void setup(Mapper.Context context)
throws IOException,
InterruptedExceptionCalled once at the beginning of the task.
Throws:
IOException
InterruptedException