2 as944985356 as944985356 于 2014.08.27 09:27 提问

线程池循环出错,关于java线程池

由于培训机构出生,对一些没常用的技术都没去学习与理解
今公司要要我做个指纹验证,用到线程池,上网也找了点资料,自己写了一下,就是循环不对。
麻烦大家给我看看吧。。。。

enter code here

//es是个ExecutorService全局变量
es = new threadPoolExecutor(5, 20, 20, TimeUnit.SECONDS,
new SynchronousQueue());

        } catch (Exception e) {
            e.printStackTrace();
        }

        for (; j < list.size(); j++) {
            System.out.println("====================================="+j);
        runMap = new HashMap<String, Object>();
        runMap.put("featureCode", list.get(j).getFeatureCode());
        runMap.put("biominiId", list.get(j).getId());
        runMap.put("userId", list.get(j).getUserId());

// es.submit(new myThread());
es.execute(new Runnable() {
public void run() {

                try {
                    Thread.sleep(2000);
                    Biomini biominis = new Biomini();
                    biominis.setFeatureCode(runMap.get("featureCode").toString());
                    DPFPTemplate template = null;
                    // byte[] curFinger =
                    // getBiominiStringToByte(biomini.getFeatureCode());
                    System.out.println("数据库:" + runMap.get("featureCode").toString()
                            + "----------" + j);
                    System.out.println("请求值:"
                            + getBiominiByteToString(featureSet.serialize()));

                    byte[] curFinger = getBiominiStringToByte(biominis
                            .getFeatureCode());
                    template = DPFPGlobal.getTemplateFactory().createTemplate(
                            curFinger);
                    if (template != null) {
                        DPFPVerificationResult result;
                        result = matcher.verify(featureSet, template);
                        if (result.isVerified()) {
                            System.out.printf("匹配到用户: %s, FAR achieved:",
                            // biominiService.queryBiominiById(Integer.parseInt(biomini.getUserId())),
                                    // (double)result.getFalseAcceptRate()/DPFPVerification.PROBABILITY_ONE);
                                    biominiService.queryBiominiById(Integer
                                            .parseInt("3213")), (double) result
                                            .getFalseAcceptRate()
                                            / DPFPVerification.PROBABILITY_ONE);
                            // 停止
                            System.out.println("线程停止");
                            es.shutdownNow();
                            return;
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });

// 线程池设置
class threadPoolExecutor extends ThreadPoolExecutor {

public threadPoolExecutor(int corePoolSize, int maximumPoolSize,
        long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue) {
    super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
}

protected void beforeExecute(Thread t, Runnable r) {
    System.out.println(t.getName());
}

protected void afterExecute(Runnable r, Throwable t) {
}

}

Csdn user default icon
上传中...
上传图片
插入图片