有很多连接的Groovy RestClient [英] Groovy RestClient with many connections

查看:140
本文介绍了有很多连接的Groovy RestClient的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Groovy RestClient我收到以下异常:

  java.lang.IllegalStateException:BasicClientConnManager的无效使用:连接仍然存在分配。 
确保在分配另一个连接之前释放连接。

据我所知,一个连接没有被释放,所以我不能再创建一个连接。



什么是可能的解决方案?



为每个呼叫创建新的RestClient?
或者也许有一些游泳池?



感谢!

解决方案

默认情况下,REST客户端使用BasicClientConnManager,它一次只能处理一个连接。为了做到并行连接,需要使用AsyncHTTPBuilder:

  DEF的HttpClient =新AsyncHTTPBuilder(
poolSize: 20,
uri:'https://www.mysite.com'


Using Groovy RestClient I am getting the following exception:

    java.lang.IllegalStateException: Invalid use of BasicClientConnManager: connection still allocated.
Make sure to release the connection before allocating another one.

As I understand that one connection has not released, so I cannot make another one.

What are the possible solutions?

Make new RestClient for every call? Or maybe there is some pool?

Thanks!

解决方案

By default the REST Client uses the BasicClientConnManager which only handles one connection at one time. In order to do concurrent connections, you need to use the AsyncHTTPBuilder:

def httpClient = new AsyncHTTPBuilder(
        poolSize: 20,
        uri: 'https://www.mysite.com'
)

这篇关于有很多连接的Groovy RestClient的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆