首页 新闻 会员 周边 捐助

前端需要后台返回状态,后台是采用多线程操作,不好控制,求教!

0
悬赏园豆:30 [待解决问题]
 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 }
cai-yigo的主页 cai-yigo | 初学一级 | 园豆:176
提问于:2013-09-04 11:40
< >
分享
所有回答(2)
0

首先定义一个公共的array   然后每个线程完毕后 向array中插入一条值

然后while循环这个数组 判断array里面的个数是否等于你启动的线程条数.如果等于则表示所有线程之行完毕

然 后跳出循环..状态就是执行完毕  where(true){

   if(array.count==count)

   }

jsasjs | 园豆:228 (菜鸟二级) | 2013-09-04 11:57
0

你是要返回什么状态??可以用静态变量存储~

幻天芒 | 园豆:37205 (高人七级) | 2013-09-04 13:27
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册