mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-23 04:25:21 +08:00
同步获取响应数据
This commit is contained in:
48
jsowell-admin/src/test/java/rpc/TestRpcClient.java
Normal file
48
jsowell-admin/src/test/java/rpc/TestRpcClient.java
Normal file
@@ -0,0 +1,48 @@
|
||||
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();
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user