xy1110 2018-11-04 06:39 采纳率: 50%
浏览 888

通过调用多线程,发现list中集合数据有3万多,但实际调用确只有1万左右,谁能帮忙解决一下

获取调用多线程的list数据:

 public String  simulatePwdLogin2(String clientId,String rownum,String type){
        //获取传过来的系统id,转化成对应的rela_cd
        //String outXml = null;
        CommConfig config=this.commConfigDaoImpl.getCommConfigByType(EamConstants.THREAD_LIMIT_COUNT);
        String code = config.getCode();
        //获得配置表中的线程并发数量
        ThreadLimitCount = Integer.parseInt(code);
        System.out.println("-----配置表中的线程并发数量 =="+ThreadLimitCount);
        //Semaphore初始化,限制并发数量
        Semaphore semaphore  = new Semaphore(ThreadLimitCount);
        try{
            try{    
                    //判断请求的client_id不能为空
                    if(StrUtil.isEmpty(clientId) || StrUtil.isEmpty(type)){
                        throw new ReqBodyValidationException();
                    }               

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

            //获取传过来的系统id,转化成对应的rela_cd
            OAuthClientSysVo clientSyscond = new OAuthClientSysVo();
            clientSyscond.setSysClientCode(clientId);
            clientSyscond = oAuthClientSysDao.loadClientSysBySysVo(clientSyscond);
            String sysCode = "";
            if(clientSyscond!=null){
                //获得系统的rela_cd
                sysCode = clientSyscond.getSysRelaCode();
            }   

            //通过rela_cd查询数据库,获得对应系统的人员数据,rownum限制获得人员的数量
            List<LdapStaffVo> staffVo = ldapService.queryStaffVo(sysCode, rownum);
            if(!StrUtil.isNullOrEmpty(staffVo)){                
                for(LdapStaffVo vo:staffVo){                    
                    if(!StrUtil.isNullOrEmpty(rownum)){
                        new WorkingThread(clientId,rownum,type,vo,oAuthClientSysDao,accountPasswdAuthHandler,logConsumer,intfLogManager,semaphore).start();
                    }else{
                        new WorkingThread(clientId,type,vo,oAuthClientSysDao,accountPasswdAuthHandler,logConsumer,intfLogManager,semaphore).start();
                    }

                    //System.out.println("----Thread.currentThread() ="+Thread.currentThread());
                    //Thread.sleep(10000);
                }
            }

        }catch(Exception e){
            e.printStackTrace();
        }
        return "ok";
    }

多线程的代码:

 private static class WorkingThread extends Thread {
        private String clientId;
        private String rownum;
        private String type;
        private LdapStaffVo vo;
        private JdbcOAuthClientSysDao oAuthClientSysDao;
        private AccountPasswdAuthHandler accountPasswdAuthHandler;
        private LogConsumer logConsumer;
        private IntfLogManager intfLogManager;
        private Semaphore semaphore;
        private WorkingThread(String clientId,String rownum,String type,LdapStaffVo vo,JdbcOAuthClientSysDao oAuthClientSysDao,
                AccountPasswdAuthHandler accountPasswdAuthHandler,LogConsumer logConsumer,IntfLogManager intfLogManager,Semaphore semaphore){
            super();
            this.clientId = clientId;
            this.rownum = rownum;
            this.type = type;
            this.vo = vo;
            this.oAuthClientSysDao = oAuthClientSysDao;
            this.accountPasswdAuthHandler = accountPasswdAuthHandler;
            this.logConsumer = logConsumer;
            this.intfLogManager = intfLogManager;
            this.semaphore = semaphore ;
        }
        private WorkingThread(String clientId,String type,LdapStaffVo vo,JdbcOAuthClientSysDao oAuthClientSysDao,
                AccountPasswdAuthHandler accountPasswdAuthHandler,LogConsumer logConsumer,IntfLogManager intfLogManager ,Semaphore semaphore){
            super();
            this.clientId = clientId;
            this.type = type;
            this.vo = vo;
            this.oAuthClientSysDao = oAuthClientSysDao;
            this.accountPasswdAuthHandler = accountPasswdAuthHandler;
            this.logConsumer = logConsumer;
            this.intfLogManager = intfLogManager;
            this.semaphore = semaphore ;
        }

        public void run(){
            //申请一个线程请求
            try {
                semaphore.acquire();
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
             System.out.println("------当前线程 :" + Thread.currentThread().getName() +"进入,当前已有" + (ThreadLimitCount - semaphore.availablePermits()) + "线程并发");

            String outXml = null;
            //获得随机的4位数
            String randomCode = PubUtil.createRandom(4);
            //获取当前的系统时间
            String format = new SimpleDateFormat("yyyyMMddhhmmssSSS").format(new Date());               
            semaphore.release();
            System.out.println("------当前线程 :" + Thread.currentThread().getName() +"离开,当前已有" + (ThreadLimitCount - semaphore.availablePermits()) + "线程并发");
            }
  • 写回答

1条回答

  • zqbnqsdsmd 2018-11-06 16:22
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 luckysheet
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱