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集终于把java给讲完了,总计3.13GB


下一篇:AtCoder Beginner Contest 157