我打电话给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();
}
}
}
如果我的代码有问题。我该如何改进呢?
答案 0 :(得分:0)
我没有看到您的代码有任何特别的错误,但您看到的错误消息听起来更像是操作系统级错误。
还有另一篇文章可能会为您解答此问题:http://support.microsoft.com/kb/2577795