Why declaring Mapper and Reducer classes as static?

后端 未结 2 1381
南笙
南笙 2020-12-15 13:56

This is likely showing my lack of Java understanding but I am wondering why in most MapReduce programs mapper and reducer classes are declared as static?

2条回答
  •  星月不相逢
    2020-12-15 14:16

    I can think of two reasons:

    1. When performing the map-reduce methods no state is needed which has to be preserved in the object. Thus all necessary information are passed to the method, no need to store additional data in the object. If the life time of the object will not exceed one method call, why should you struggle then with instantiation?
    2. It does not make sense to have more than one object of it, similar reasons for which you would implement the Singleton Pattern.

提交回复
热议问题