157-模拟高并发代码

Posted pogusanqian

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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();

 

以上是关于157-模拟高并发代码的主要内容,如果未能解决你的问题,请参考以下文章