其他分享
首页 > 其他分享> > 157-模拟高并发代码

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();

 

标签:historyAverageRate,157,并发,线程,100,executorService,模拟,1000
来源: https://www.cnblogs.com/pogusanqian/p/12815208.html