我是否会产生更多线程然后我认为我在我的映射器中?

时间:2013-07-17 18:50:33

标签: java hadoop emr

我正在尝试使用Web解析器,因为本质上存在停机时间,而程序从我检索文档时使其成为多线程。想法是我的线程从URL堆中检索URLS。当我在具有中等实例的EMR上运行程序时,这使程序的速度增加了三倍。在大型实例中,我出现了内存错误。我只需要更少的线程,或者线程的数量不那么严格控制,那么我认为它是什么?这是我的映射器:

public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, Text> {
        private Text word = new Text();
        private URLPile pile= new URLPile();

        @Override
        public void map(LongWritable key, Text value, OutputCollector<Text, Text> output, Reporter reporter)  {

            // non english encoding list, all others are considered english to
            // avoid missing any
            String url = value.toString();
            StringTokenizer urls = new StringTokenizer(url);
            Config.LoggerProvider = LoggerProvider.DISABLED;
            MyThread[] Threads = new MyThread[8];
            for(MyThread thread : Threads){
                thread = new MyThread(output,pile);
                thread.start();
            }

                while (urls.hasMoreTokens()) {
                    try{

                        if(urls.hasMoreTokens()){
                            word.set(urls.nextToken());
                            String currenturl= word.toString();   
                             pile.addUrl(currenturl);
                        }else{
                            System.out.println("out of tokens");
                            pile.waitTillDone();
                        }


                    } catch (Exception e) {
                        /*

                         */
                        continue;
                    }


                }


        }

}

0 个答案:

没有答案