日期:2014-05-20 浏览次数:20683 次
ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(); cm.setMaxTotal(100); cm.setDefaultMaxPerRoute(5); httpclient = new DefaultHttpClient(cm); Thread th1 = new Thread(){ public void run(){ ExecutorService executor = Executors.newCachedThreadPool(); for(int i=0;i<10;i++){ executor.execute(new exe_post()); } executor.shutdown(); while(!executor.isTerminated()){ } System.out.println("Thread1 is end"); }};
class exe_post implements Runnable{ public void run(){ try { HttpPost httpost = new HttpPost("http://www.xxx.com"); ...... ...... httpclient.execute(httpost); HttpEntity entity = response.getEntity(); 判断entity内容 } catch (Exception e) { e.printStackTrace(); } } }