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 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退