I define the httpclient like this way,when serval requset call the execute method,I find that some method retuslt is the same,How to fix this bug? Now I want to lock the execute method.It that right?
//defind global variable:client
Registry<ConnectionSocketFactory> reg = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", new PlainConnectionSocketFactory())) .build();
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(reg);
client = HttpClients.custom()
.setConnectionManager(cm).build();
//call method
synchronized (this) {
HttpResponse response = client.execute(get);
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
System.out.println(EntityUtils.toString(response.getEntity()));
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…