Java 多线程递归,Java多线程递归如何弥补管理漏洞

副标题:Java多线程递归如何弥补管理漏洞

时间:2024-02-25 05:00:01 阅读: 最新文章 文档下载
说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

【#教育# 导语】Java多线程递归在我们使用的时候需要我们不断的进行学习,其实每个语言都可以在源代码中找到问题的解决方案。当每个迭代彼此独立,并且完成Java多线程递归中每个迭代的工作,意义都足够重大,足以弥补管理一个新任务的开销时,这个顺序循环是适合并行化的。

  1.public voidParallelRecursive(final Executorexec,

  List>nodes,Collection results){

  2.for(Node n:nodes){

  3.exec.execute(new Runnable(){

  4.public void run(){

  5.results.add(n.compute());

  6.}

  7.});

  8.parallelRecursive(exec,n.getChildren(),results);

  9.}

  10.}

  11.publicCollectiongetParallelResults(List>nodes)

  12.throws InterruptedException{

  13.ExecutorService exec=Executors.newCachedThreadPool();

  14.Queue resultQueue=newConcurrentLinkedQueue();

  15.parallelRecursive(exec,nodes,resultQueue);

  16.exec.shutdown();

  17.exec.awaitTermination(Long.MAX_VALUE,TimeUnit.SECONDS);

  18.return reslutQueue;

  19.}

Java多线程递归如何弥补管理漏洞.doc

本文来源:https://www.wddqw.com/XRxI.html