public static void shutdown() { try { Unirest.shutdown(); } catch (Exception e) { } }
public void destroy() { try { Unirest.shutdown(); } catch (IOException e) { e.printStackTrace(); } }
static void shutdown() { try { Unirest.shutdown(); } catch (Exception e) { logger.warn("Error while closing rest client", e); } }
public void destroy() { try { Unirest.shutdown(); } catch (IOException e) { e.printStackTrace(); } }
public void close() { try { Unirest.shutdown(); } catch (IOException e) { e.printStackTrace(); } } }
public static void main(String[] args) throws Exception { int thread_num = 10; int client_num = 10; final String tokenUrl = "https://openapi.baidu.com/social/oauth/2.0/token"; ExecutorService exec = Executors.newCachedThreadPool(); // 50个线程可以同时访问 final Semaphore semp = new Semaphore(100); // 模拟460个客户端访问 long ftime = System.currentTimeMillis(); for (int index = 0; index < client_num; index++) { Runnable run = new Runnable() { public void run() { try { org.json.JSONObject json = AsynHttpUtil.post(tokenUrl, null); } catch (Exception e) { e.printStackTrace(); } } }; exec.execute(run); } // 退出线程池 long etime = System.currentTimeMillis(); log.info("AsynhttpUtil同步方式执行" + thread_num + "个并发访问 " + client_num + "个客服端所花费的时间 " + (etime - ftime) + " ms"); Unirest.shutdown(); exec.shutdown(); }
@Override public void shutdown(boolean free) { getAudioManager().closeAudioConnection(); client.close(); authToken = null; //make further requests fail if (free) { try { Unirest.shutdown(); } catch (IOException ignored) {} } }
Unirest.shutdown(); } catch (Exception e) { print_error("Error shutting down Unirest");
@Override public void onExecutionFinish() { try { Unirest.shutdown(); } catch (IOException e) { logger.error("Cannot stop unirest", e);