类中添加日志打印

 利用log4j

package org.apache.giraph.examples;

import java.io.IOException;
import org.apache.giraph.edge.Edge;
import org.apache.giraph.graph.BasicComputation;
import org.apache.giraph.graph.Vertex;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.log4j.Logger;

public class InlinkCountComputation extends BasicComputation{
	  private static final Logger LOG = Logger.getLogger(InlinkCountComputation.class);
	
	  @Override
	  public void compute(Vertex vertex,
	      Iterable messages) throws IOException {
		  if(getSuperstep() == 0) {
			  vertex.setValue(new IntWritable(0));
			  for (Edge edge : vertex
						.getEdges()) {
				  sendMessage(edge.getTargetVertexId(),new IntWritable(1));
			  }
		  } else {
			  for (IntWritable message : messages) { 
				  vertex.setValue( new IntWritable(vertex.getValue().get() + message.get()));
			  }
			  vertex.voteToHalt();
		  }
	  }
}

 

你可能感兴趣的:(Java多线程)