在stackowerflow上已经存在类似的问题:link。 但它的内容对我来说太难了,我无法理解lambda的表达。
我只需要将下面的简单Java代码转换为Equivalent C#.net代码。
ExecutorService pool = null;
pool = Executors.newFixedThreadPool(BaseBlockUtil.THREAD_NUN);
CompletionService<BlockObject> completionService = new ExecutorCompletionService<BlockObject>(pool);
int runnerThread = 0;
foreach (BlockObject blockObject in putExtra.processes)
{
runnerThread++;
while (runnerThread > (BaseBlockUtil.THREAD_NUN + 1))
{
completionService.take().get();
runnerThread--;
}
BlockUpload task = new BlockUpload(blockObject, jsonObjectRet, putExtra, token, httpClient, uploadBatch);
completionService.submit(task);
}
for (int i = 0; i < runnerThread; i++)
{
completionService.take().get();
}
pool.shutdown();
对于&#39; ExcutorService&#39;,我可以考虑使用C#&#39; ThreadPool&#39;替换它。但是对于ExcutorCompletionService&#39; ,我在谷歌搜索了一天,什么都没有。
关于&#39; ExcutorCompletionService&#39;的功能,您可以参考此When should I use a CompletionService over an ExecutorService?