gearman 处理类


import java.util.ArrayList;
import java.util.List;

import org.gearman.client.GearmanJobResult;
import org.gearman.client.GearmanJobResultImpl;
import org.gearman.util.ByteUtils;
import org.gearman.worker.AbstractGearmanFunction;
//真正的业务逻辑
public class ReverseFunction extends AbstractGearmanFunction {
    
    public GearmanJobResult executeFunction() {
    	GearmanJobResult gjr=null;
      //  StringBuffer sb = new StringBuffer(ByteUtils.fromUTF8Bytes((byte[]) this.data));
        for(int i=0;i<10;i++){
        	 StringBuffer sb = new StringBuffer(ByteUtils.fromUTF8Bytes((byte[]) this.data));
        	
         gjr = new GearmanJobResultImpl(this.jobHandle,
                true, sb.reverse().toString().getBytes(),
                new byte[0], new byte[0], 0, 0);
         System.out.println("--"+sb.toString()+"--");
         try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        }
        return gjr;
    }
}
class show extends Thread{
	  public void run(){
		  ClientTest test=new ClientTest("192.168.101.143", 4730);
             System.out.println(test.reverse("hello"));
  }
 }

你可能感兴趣的:(java,thread)