Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling ExecutorService.shutdown in a dynamic thread number
    text
    copied!<p>Good Morning in my timezone.</p> <p>I am using thread pool to develop a little Http robot that travels from link to link in each page.When i found a new link i create a new thread that will explore that new page. Pseudo code.</p> <pre><code>pool = Executors.newFixedThreadPool(40); pool.execute(new Exploit(tree.getRoot())); </code></pre> <p>In this case the Exploit is a inner class that implements Runnable interface and have access to pool, so each time one thread finds a link, will use the pool to add a new "thread" like this way:</p> <pre><code>for(Link n : links){ pool.execute(new Exploit(n)); } </code></pre> <p>I saw a lot of examples using ExecutorService class but all of them use the same sort of code like this :</p> <pre><code>ExecutorService executor = Executors.newFixedThreadPool(NTHREDS); for (int i = 0; i &lt; 500; i++) { Runnable worker = new MyRunnable(10000000L + i); executor.execute(worker); } // This will make the executor accept no new threads // and finish all existing threads in the queue executor.shutdown(); </code></pre> <p>In the above code , the number the threads is static so when the code calls shutdown all the threads had already been added to the pool.I can not follow this code because in my case i do not have a static number of threads to add. My stop condition to add more threads to the pool is when i reached a searching deep level.So my question is , how do i call executor.shutdown in the main thread ? Is there any kind of join that i can use in the main thread ? </p> <p>Thanks in advance. Best Regards</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload