1

我正在打电话REST URL并试图衡量需要多少时间才能得到回复。

我正在使用DefaultHttpClient它来从REST URL.

在我下面的程序中,每个线程都将在特定范围内工作。就像每个线程将在之间工作1 - 100,第二个线程将在101 - 200等之间工作。

所以在我下面的代码中,它有时对我有用,但过了一段时间它会抛出异常

Failure initializing default SSL context

还有这个错误——

I/O exception (java.net.SocketException) caught when connecting to the target host: No buffer space available (maximum connections reached?): connect

我在这里做错了什么吗?-或者我可以使用任何更好的客户端DefaultHttpClient来进行 RESTFUL 调用。

下面是我的代码-

class Task implements Runnable {

private DefaultHttpClient httpclient;
private HttpResponse response;

    @Override
    public void run() {

        try {

            for (int userId = id; userId < id + noOfTasks; userId++) {

                httpclient = new DefaultHttpClient();

               HttpGet httpGet = new HttpGet("http://localhost:8080/service/BEService/v1/get/USERID=10000/profile.ACCOUNT.SERVICE");

                long start = System.nanoTime();

                response = httpclient.execute(httpGet);

                long end = System.nanoTime() - start;

                HttpEntity entity = response.getEntity();
                EntityUtils.consume(entity);
                }
        } catch (Exception e) {
            LOG.error("Threw a Exception in " + getClass().getSimpleName(), e);
        } finally {
        httpclient.getConnectionManager().shutdown();
    }
    }
}

如果我的代码有任何问题。我该如何改进它?

4

1 回答 1

0

我没有看到您的代码有任何特别错误,但您看到的错误消息听起来更像是操作系统级别的错误。

还有另一篇文章可能会为您回答这个问题:http: //support.microsoft.com/kb/2577795

于 2013-07-21T11:00:44.807 回答