157-模拟高并发代码

        //创建一个线程池,规定只能处理100个线程,但是我们会创建1000个线程,用来模拟多线程访问数据库
        ExecutorService executorService = Executors.newFixedThreadPool(100);
        for (int i = 0; i < 1000; i++) {
            executorService.submit(new Runnable() {
                @Override
                public void run() {
                    //获取平台历史年化收益率
                    Double historyAverageRate = lonInfeService.quaryhistoryAverageRate();
                    model.addAttribute(Constant.HISTORY_AVERAGE_RATE, historyAverageRate);
                }
            });
        }

        executorService.shutdown();

 

posted on 2020-05-01 22:43  十年磨三劍  阅读(160)  评论(0编辑  收藏  举报

导航