通过调用多线程,发现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个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!