PHP中文网2017-04-18 10:14:23
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.
PHP中文网2017-04-18 10:14:23
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