有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java StringUtils并发异常

我得到以下错误:

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#

怎么了?代码位于实现可调用的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;
    }

共 (0) 个答案