1.iterator遍历共用一个对象
- 为什么要这样设置:大数据处理的数据往往是海量,每次循环遍历都new对象,导致大量的性能被消耗。在这种海量数据处理的场景下,性能优化是非常重要的。
- 问题重现:
reduce的Iterable迭代器中的内容是a,b,c这三条,然后把这三条数据加入到List中然后遍历List的时候发现显示的结果是c,c,c
public class MyReducer extends Reducer<LongWritable, Text,LongWritable,Text> {
ArrayList<Strnig> str = new ArrayList<Strnig>();
@Override
protected void reduce(LongWritable key, Iterable<String> values, Context context) {
for (String value : values)