1 public class TestTg extends BaseTg { 2 3 4 public void testee() throws Exception { 5 ExecutorService exe= Executors.newFixedThreadPool(15); 6 Map<String, String> flagMap = new HashMap<String, String>(); 7 for (int i = 0; i < urisToGet.size(); i++) { 8 HttpPost httpget = new HttpPost(urisToGet.get(i)); 9 exe.execute(new GetThread(httpClient, httpget)); 10 } 11 12 } 13 14 class GetThread extends Thread { 15 private final HttpClient httpClient; 16 private final HttpContext context; 17 private final HttpPost httpget; 18 public GetThread(HttpClient httpClient, HttpPost httpget 19 ) { 20 this.httpClient = httpClient; 21 this.context = new BasicHttpContext(); 22 this.httpget = httpget; 23 } 24 25 @Override 26 public void run() { 27 this.setName("threadsPoolClient"); 28 try { 29 Thread.sleep(5000); 30 } catch (InterruptedException e) { 31 e.printStackTrace(); 32 } 33 get(); 34 35 } 36 37 public void get() { 38 try { 39 HttpResponse response = this.httpClient.execute(this.httpget, 40 this.context); 41 HttpEntity entity = response.getEntity(); 42 if (entity != null) { 43 } else { 44 } 45 EntityUtils.consume(entity); 46 } catch (Exception ex) { 47 this.httpget.abort(); 48 } finally { 49 httpget.releaseConnection(); 50 } 51 } 52 } 53 }
首先定义一个公共的array 然后每个线程完毕后 向array中插入一条值
然后while循环这个数组 判断array里面的个数是否等于你启动的线程条数.如果等于则表示所有线程之行完毕
然 后跳出循环..状态就是执行完毕 where(true){
if(array.count==count)
}
你是要返回什么状态??可以用静态变量存储~