是否有一个轻量级的REST客户端框架可以并行构建请求?

时间:2019-02-11 22:57:31

标签: java rest http kotlin unirest

我爱Unirest,我确实喜欢...

不幸的是,它似乎不是很安全的线程。

我试图并行处理我的请求:

runBlocking {
    for (a in 0..9) async{
        for (b in 0..9) async{
            for (c in 0..9) async{
                if (!found) Unirest.post(targetURL)
                    .body(String.format(requestTemplate, a, b, c))
                    .asStringAsync(object : Callback<String> {...})
            }
        }
    }
}

我所获得的只是

Feb 11, 2019 11:44:51 PM org.apache.http.impl.nio.client.InternalHttpAsyncClient run
SEVERE: I/O reactor terminated abnormally
com.mashape.unirest.http.exceptions.UnirestException: java.net.ConnectException
    at com.mashape.unirest.http.HttpClientHelper$1.failed(HttpClientHelper.java:86)
    at org.apache.http.concurrent.BasicFuture.failed(BasicFuture.java:134)
    at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.failed(AbstractClientExchangeHandler.java:419)
    at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.connectionRequestFailed(AbstractClientExchangeHandler.java:335)
    at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.access$100(AbstractClientExchangeHandler.java:62)
    at org.apache.http.impl.nio.client.AbstractClientExchangeHandler$1.failed(AbstractClientExchangeHandler.java:378)
    at org.apache.http.concurrent.BasicFuture.failed(BasicFuture.java:134)
    at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager$InternalPoolEntryCallback.failed(PoolingNHttpClientConnectionManager.java:503)
    at org.apache.http.concurrent.BasicFuture.failed(BasicFuture.java:134)
    at org.apache.http.nio.pool.RouteSpecificPool.timeout(RouteSpecificPool.java:170)
    at org.apache.http.nio.pool.AbstractNIOConnPool.requestTimeout(AbstractNIOConnPool.java:560)
    at org.apache.http.nio.pool.AbstractNIOConnPool$InternalSessionRequestCallback.timeout(AbstractNIOConnPool.java:821)
    at org.apache.http.impl.nio.reactor.SessionRequestImpl.timeout(SessionRequestImpl.java:182)
    at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processTimeouts(DefaultConnectingIOReactor.java:212)
    at org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor.processEvents(DefaultConnectingIOReactor.java:157)
    at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:350)
    at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.execute(PoolingNHttpClientConnectionManager.java:191)
    at org.apache.http.impl.nio.client.CloseableHttpAsyncClientBase$1.run(CloseableHttpAsyncClientBase.java:64)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.net.ConnectException
    ... 10 more

在没有async的情况下,代码可以正常运行,因此我将错误归咎于并发访问非并发访问的资源。 (如果我对此有误,请祈祷。)

是否存在轻量级的客户端框架却允许这种并行化?

0 个答案:

没有答案