package rpc; import java.util.concurrent.TimeUnit; public class TestRpcClient { public static void main(String[] args) throws Exception{ //Channel channel = new RpcClient().connect("127.0.0.1", 8888); Thread thread1 = new Thread(new Runnable() { @Override public void run() { RpcRequest rpcRequest = new RpcRequest(); rpcRequest.setParam("参数1"); try { System.out.println("thread1发送请求"); RpcResponse rpcResponse = RpcUtil.send(rpcRequest, 5, TimeUnit.SECONDS); System.out.println("thread1处理结果:" + rpcResponse); } catch (Exception e) { throw new RuntimeException(e); } } }); Thread thread2 = new Thread(new Runnable() { @Override public void run() { RpcRequest rpcRequest2 = new RpcRequest(); rpcRequest2.setParam("参数2"); try { System.out.println("thread2发送请求"); RpcResponse rpcResponse = RpcUtil.send(rpcRequest2, 2, TimeUnit.SECONDS); System.out.println("thread2处理结果:" + rpcResponse); } catch (Exception e) { throw new RuntimeException(e); } } }); // 休眠一下,等待客户端与服务端进行连接 Thread.sleep(1000); thread1.start(); thread2.start(); } }