Java 在map reduce中使用util类中的静态变量
我有一个映射器、还原器和一个util类Java 在map reduce中使用util类中的静态变量,java,hadoop,static,mapreduce,Java,Hadoop,Static,Mapreduce,我有一个映射器、还原器和一个util类 - The util class has a static class variable int a=0 and a static method doSomething() which calls another static method add() which increment a by 1. - I call the UtilClass.doSomething() from the reducer. - When I try to pr
- The util class has a static class variable int a=0
and a static method doSomething() which calls another static method
add() which increment a by 1.
- I call the UtilClass.doSomething() from the reducer.
- When I try to print the final value of "a" in
doSomething() using
context.getCounter("doSomethign method","value of a").increment(1);,
the value says 1229 which is weird since the reduce task received only 240 keys
- A total of 30 reducers are spawned.
下面是一个示例代码块。我在避免一些样板代码。
注意:这是以分布式方式运行的,而不是独立运行的
class MyMapper extends Reducer{
public reduce(<params>){
UtilClass.doSomething(context);
}
}
class UtilClass{
public static int a=0;
public static void add(){
a=a+1;
}
public static void doSomething(Reducer.Context context){
add();
// This is printing 1229 in the end, instead of 240 which is the number of key given to the reducer
context.getCounter("doSomethign method","value of a").increment(1);
}
}
类MyMapper扩展了Reducer{
公共资源(减少){
UtilClass.doSomething(上下文);
}
}
类UtilClass{
公共静态int a=0;
公共静态void add(){
a=a+1;
}
公共静态void doSomething(Reducer.Context){
添加();
//最后打印的是1229,而不是240,240是提供给减速器的键数
getCounter(“doSomethign方法”,“a的值”)。增量(1);
}
}
这就引出了以下问题
您使用的是哪个版本的hadoop?@BinaryNerd hadoop 2.6.0.2.2.0.0.-2041您使用的是哪个版本的hadoop?@BinaryNerd hadoop 2.6.0.2.0.0.-2041