// 创建一个定长线程池,可控制线程最大并发数,超出的线程会在队列中等待:

 

private ExecutorService fixedThreadPool;

 

// 创建一个定长线程池,可控制线程最大并发数,超出的线程会在队列中等待:
  fixedThreadPool = Executors.newFixedThreadPool(1);

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
fixedThreadPool.execute(new Runnable() {
            @Override
            public void run() {
                HashMap<String, Object> map = null;
                try {
                    String result = Net.login(Constant.login_url, "phone",
                            phoneNumber, "password", password);
                    // Log.i("返回", result);
                    // 解析json字符串
                    result = result.substring(1, result.length() - 1);
                    Log.i("登录结果", result);
                    JSONObject jsonObject = new JSONObject(result);
                    map = new HashMap<String, Object>();
                    // Log.i("结果", jsonObject.get("message")+"");
                    // 登录结果信息
                    map.put("message", jsonObject.getString("message"));
                    // 状态码
                    map.put("status", jsonObject.getString("status"));
                    // 如果用户登录成功则将标识码和用户id存起来
                    if ("10000".equals(jsonObject.getString("status"))) {
                        // 保存用户头像
                        Constant.userIc = Net.getBitmap(jsonObject
                                .getString("portrait"));
                        // 用户标识码
                        map.put("sigen", jsonObject.getString("sigen"));
                        // 上传头像用的key
                        map.put("key", jsonObject.getString("key"));
                        // 用户id
                        map.put("userid", jsonObject.getString("userid"));
                        // 总积分
                        map.put("integral", jsonObject.getString("integral"));
                        // 用户头像
                        map.put("portrait", jsonObject.getString("portrait"));
                    }
                    list.add(map);
                    // 通知UI
                    Message msg = new Message();
                    msg.obj = "ok";
                    handler.sendMessage(msg);
                } catch (Exception e) {
                    e.printStackTrace();
                    // 通知UI
                    Message msg = new Message();
                    msg.obj = "no";
                    handler.sendMessage(msg);
                }
            }
        });