- 什麼是目前運行(上下文)方法的默認行爲。
默認的實現是在爲Mapper類Apache的Hadoop的源代碼可見:
/**
* Expert users can override this method for more complete control over the
* execution of the Mapper.
* @param context
* @throws IOException
*/
public void run(Context context) throws IOException, InterruptedException {
setup(context);
try {
while (context.nextKeyValue()) {
map(context.getCurrentKey(), context.getCurrentValue(), context);
}
} finally {
cleanup(context);
}
}
總結:對於一次性初始化
- 呼叫
setup
。
- 迭代輸入中的所有鍵 - 值對。
- 將密鑰和值傳遞給
map
方法實現。
- 致電
cleanup
一次性拆解。
- 如果我重寫運行(上下文)會得到什麼樣的特殊控制的按文件?
默認實現總是遵循單個線程中的特定執行順序。重寫此代碼很少見,但它可能爲高度專業化的實現(如不同的線程模型或嘗試合併多餘的密鑰範圍)提供了可能性。
- 是否有人在您的實現中重寫了此方法?
在Apache的Hadoop的代碼庫,存在的這種兩所覆蓋:
ChainMapper
允許單個地圖任務內執行鏈接多個Mapper
類實現在一起。覆蓋run
設置代表鏈的對象,並通過該映射器鏈傳遞每個輸入鍵/值對。
MultithreadedMapper
允許多線程執行另一個Mapper
類。 Mapper
類必須是線程安全的。 run
的覆蓋將啓動多個線程迭代輸入鍵值對並將它們傳遞給底層的Mapper
。