简体   繁体   English

使用 ExecutorSERvice、Runnable 进行迭代

[英]Iteration using ExecutorSErvice, Runnable

In a service implementation following is the implementation在服务实现中,以下是实现

    if(usernames != null && usernames.size() > 0) {

        operationId = bulkUpdateAuditLogRepository.getLatestOperationId()
        for(String username: usernames) {
            executorService.submit(new BackgroundTask() {
                @Override
                public void doTask() {
                    deactivateUserInternal(username, operationId)
                }
            })
        }
    }

Also private ExecutorService executorService = Executors.newFixedThreadPool(5);还有私有 ExecutorService executorService = Executors.newFixedThreadPool(5);

anyhow while iterating the loop only the last username of any array ['AAAAA', 'BBBB', 'CCCC'], only the value CCCC is taken up by the runnable BackgroundTask instance.无论如何,在迭代循环时,只有任何数组 ['AAAAA', 'BBBB', 'CCCC'] 的最后一个用户名,只有值 CCCC 被可运行的 BackgroundTask 实例占用。 Just want to know what is missing in the iteration.只想知道迭代中缺少什么。

The backgroundTask mentioned was not a java.util.concurrent.Callable, after such implementation able to get the executing in an async manner.提到的 backgroundTask 不是 java.util.concurrent.Callable,在这样的实现之后能够以异步方式执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM