如何关闭Java的CloseableHttpClient中的保持活动状态?

时间:2019-04-04 22:22:57

标签: java perl

我正在尝试使用 CloseableHttpClient 通过Spring Boot将此Perl代码转换为Java代码,但是在Java中,获取事件非常慢。如何将保持活动状态设置为0?

Perl:

use strict;
use LWP::UserAgent;
use HTTP::Headers;

my $ua = LWP::UserAgent->new('keep_alive' =>  0, timeout => 7200);

while (1)
{
    my $request = HTTP::Request->new("GET",'https://events.voip.ovh.net', HTTP::Headers->new(), "\n\n");
    my $response = $ua->request($request);
    if ($response->is_success)
    {
        print $response->content."\n";
    }
}

Java:

CloseableHttpClient configureCloseableHttpclient() {
    RequestConfig config = RequestConfig.custom()
            .setSocketTimeout(5 * 1000)
            .setConnectTimeout(5 * 1000).build();
    return HttpClients.custom().setConnectionManager(new PoolingHttpClientConnectionManager()).setDefaultRequestConfig(config)
            .build();
}

0 个答案:

没有答案