我收到以下错误:
Caused by: java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901)
at java.util.ArrayList$Itr.next(ArrayList.java:851)
at org.apache.commons.lang3.StringUtils.join(StringUtils.java:3428)
at org.apache.commons.lang3.StringUtils.join(StringUtils.java:3513)
用于跑步StringUtils.join
StringUtils
文档提到:#ThreadSafe#
怎么了?该代码位于实现 Callable 的 java 类中。
我的完整代码:
public class MyApiCallable implements Callable<ResponseType> {
final List<String> itemsId;
MyApiCallable(List<String> itemsId) {
this.itemsId = itemsId;
}
@Override
public ResponseType call() throws Exception {
Client client = ClientBuilder.newClient();
WebTarget baseTarget = client.target("http://whatever.com").path("path").queryParam("ItemID", StringUtils.join(itemsId,",",));
ResponseType rs = target.request().get(ResponseType.class);
return rs;
}
}
这是调用可调用的方法:
private Future<ResponseType> addGetMultipleItems(ExecutorService executor, List<String> itemIds) {
Callable<ResponseType> shoppingCallable = new MyApiCallable(itemIds);
Future<ResponseType> shoppingResult = executor.submit(shoppingCallable);
return shoppingResult;
}