参考链接
运行过程
对异步远程服务调用的并发测试下报:
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());
}
}
责任链模式
装饰器模式