51,409
社区成员
发帖
与我相关
我的任务
分享
结果是固定值 1、1、1、1、
package com.example.springboot;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* @作者: 杨得印
* @创建时间: 2019/8/10
* @描述: Test
*/
public class Test {
public static void main(String[] args) {
List<String> strs=new ArrayList<>();
strs.add("1");
strs.add("2");
strs.add("3");
strs.add("4");
ExecutorService executorService=Executors.newFixedThreadPool(5);
for (int i=0;i<10;i++) {
executorService.execute(new Runnable() {
@Override
public void run() {
new Test().delete(strs);
}
});
}
}
public void delete(List<String> strs){
strs.add("123");
strs.add("456");
strs.add("789");
for (int i = 0; i < strs.size(); i++) {
strs.remove(i);
}
System.out.println(Thread.currentThread().getName()+"="+strs.size());
}
}