Java bug Cant保留了counter的值

时间:2012-05-08 12:40:32

标签: java loops mapreduce

我的计数器值每次都在写入。不能找出保持值增加的方法。这个地图减少代码。需要使用profileId设置计数器的值。感谢

public void map(Object key, Text value, Context context) throws IOException, InterruptedException {

    String profile;
    String pos = null;
    int count=0;
    StringTokenizer inputKey=new StringTokenizer(value.toString()," ,");

    while(inputKey.hasMoreTokens()) {
        String input=inputKey.nextToken();
        System.out.println("the input is "+ input);

        if(!input.endsWith("</id>")) {
            textInput.set(input);
            count++;
            System.out.println("value of count is " + count);
        } else {
            profile=input.substring(4,15);
            profileId.set(profile);
        }

        /*count=+count;
          int index=value.toString().indexOf(count);
          pos=Integer.toString(index);
          System.out.println("the position is " + pos);
        */
        System.out.println("the index for each word is " + pos ); 
        context.write(textInput, new Text(profileId + ", " + pos));
    }
}

0 个答案:

没有答案