Java多线程操作集合的小问题
PHP中文网
PHP中文网 2017-04-18 10:12:23
0
4
311
PHP中文网
PHP中文网

认证0级讲师

reply all(4)
洪涛
ExecutorService exec = Executors.newFixedThreadPool(8);
for(final Object obj : list){
    exec.execute(new Runnable() {
        @Override
        public void run() {
            process(obj)
        }
    });
}

I think this method is better.

迷茫

java8 parallel stream

洪涛

The member variable index is a multi-thread shared variable. You need to add volatile to ensure the visibility of this variable in multi-threads. The declaration code is changed to the following:

private volatile int index = 0;

Specifically why please learn the basic knowledge related to java concurrent programming

迷茫

It’s best to use thread synchronization in your run()

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!