java—当serval requset同时调用execute时,如何使httpclient成为安全线程?

h7wcgrx3  于 2021-06-26  发布在  Java
关注(0)|答案(0)|浏览(215)

我这样定义httpclient,当serval requset调用execute方法时,我发现有一个方法retuslt是一样的,如何修复这个bug?现在我想锁定execute方法,对吗?

//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())); 
            } 
        }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题