Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 是否在映射程序之间共享FSDataInputStream?_Java_Database_Hadoop_Mapreduce_Hdfs - Fatal编程技术网

Java 是否在映射程序之间共享FSDataInputStream?

Java 是否在映射程序之间共享FSDataInputStream?,java,database,hadoop,mapreduce,hdfs,Java,Database,Hadoop,Mapreduce,Hdfs,我有一份工作,我想在多个映射程序中访问同一个文件。起初,我尝试在每个映射器中打开并查找该文件,但结果证明速度非常慢 是否可以在run()方法中打开文件(在这里我可以执行job.SetOutputPath等操作),然后与映射程序共享此打开的文件,这样我就不会有100多个映射程序单独打开同一个文件的惊人开销?是的,这实际上是可能的。如果在作业开始之前设置分布式缓存并将文件加载到其中,它将自动发送到映射程序 分布式缓存设置示例: String fileLocation;//set this to fi

我有一份工作,我想在多个映射程序中访问同一个文件。起初,我尝试在每个映射器中打开并查找该文件,但结果证明速度非常慢


是否可以在
run()
方法中打开文件(在这里我可以执行
job.SetOutputPath
等操作),然后与映射程序共享此打开的文件,这样我就不会有100多个映射程序单独打开同一个文件的惊人开销?

是的,这实际上是可能的。如果在作业开始之前设置分布式缓存并将文件加载到其中,它将自动发送到映射程序

分布式缓存设置示例:

String fileLocation;//set this to file absolute location
Configuration conf; //job Configuration

DistributedCache.addLocalFiles(conf,fileLocation);
conf.set("fileLocation",fileLocation);
在映射器设置方法中检索:

Configuration mapConf = context.getConfiguration();

URI[] cacheURIArray = DistributedCache.getCacheFiles();

String file2Location = mapConf.get("file2Location");

List<String> fileWords = new ArrayList<String>(); //set this as a clas variable so it can be accessed outside of the setup method of the mapper

for(URI uri: cacheURIArray){
    if( uri.toString().matches(".*"+fileLocation)){
        BufferedReader br = new BufferedReader(new InputStream(cacheFileSystem.open(new Path(uri.toString()))));
        String line = "";
        line = br.readLine();
        while(line != null){
            fileWords.add(line);
            line = br.readLine();
        }
    }
}
Configuration-mapConf=context.getConfiguration();
URI[]CacheUrArray=DistributedCache.getCacheFiles();
字符串file2Location=mapConf.get(“file2Location”);
List fileWords=new ArrayList()//将其设置为clas变量,以便可以在映射器的设置方法之外访问它
for(URI:CacheUrray){
if(uri.toString().matches(“.*”+文件位置)){
BufferedReader br=new BufferedReader(新输入流(cacheFileSystem.open)(新路径(uri.toString())));
字符串行=”;
line=br.readLine();
while(行!=null){
添加(行);
line=br.readLine();
}
}
}
您的检索方法可能至少与我提供的示例有所不同,但它用于说明如何使用分布式缓存。有关更多信息,请查看