手写rpc问题清单

手写rpc问题清单

参考链接

轻量级分布式 RPC 框架

一个轻量级分布式RPC框架–NettyRpc

运行过程

在这里插入图片描述

对异步远程服务调用的并发测试下报:
java.lang.RuntimeException: Timeout exception. Request id: c9a388ca-a12b-4641-a380-8f60927152cb. Request class name: org.lmj.client.HelloService. Request method: hello

单个请求是没有问题的。

public class RPCFuture implements Future<Object> {
//..................
  @Override
    public Object get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
        boolean success = sync.tryAcquireNanos(-1, unit.toNanos(timeout));//问题就在这行代码,它在并发下就会出现问题。两个线程竞争都不行
      
        if (success) {
            if (this.response != null) {
                return this.response.getResult();
            } else {
                return null;
            }
        } else {
            throw new RuntimeException("Timeout exception. Request id: " + this.request.getRequestId()
                    + ". Request class name: " + this.request.getClassName()
                    + ". Request method: " + this.request.getMethodName());
        }
    }

责任链模式
装饰器模式

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值