In the source code of Hadoop, the base class Mapper class and the Reducer class contain only four methods: The Setup method, the cleanup method, the Run method, and the map method. As shown below:
The method is called in the Run method, as follows:
As you can see, the above three methods are called in the Run Method: The Setup method, the map method, and the cleanup method. The Setup method and the cleanup method do not do anything by default, and they are executed only once. However, the Setup method usually performs some preparatory work before the map function, such as some configuration information of the job, etc., the cleanup method is executed after the map method is run, and the method is to complete some end cleanup tasks, such as: resource release, etc. If you need to do some configuration and cleanup work, you need to rewrite the mapper/reducer subclasses to implement the appropriate functionality. The map method is re-implemented in the corresponding subclass, which is our custom map method. This method is inside a while loop, indicating that the method is executed many times. The Run method is the method that each maptask invokes.
The Setup method and cleanup method in Mapper class/reducer class and the introduction of the Run method