Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From your comments:</p> <blockquote> <p>i need to know that if pool is idle or pool can accept the tasks. if pool can accept, i need to know how much free threads in the pool. if it is 5 i will send 5 tasks to the pool to do the processing.</p> </blockquote> <p>I don't think that you should be doing the pool accounting yourself. For your thread pool if you use <code>Executors.newFixedThreadPool(5)</code> then you can submit as many tasks as you want and it will only run them in 5 threads.</p> <blockquote> <p>so i get the first most 5 tasks from the vector and assign them to the pool.ignore the other tasks in the vector since they may be update / remove from a separate cycle</p> </blockquote> <p>Ok, I see. So you want to maximize parallelization while at the same time not pre-loading jobs? I would think that something like the following pseudo code would work:</p> <pre><code> int numThreads = 5; ExecutorService threadPool = Executors.newFixedThreadPool(numThreads); List&lt;Future&lt;MyJob&gt;&gt; futures = new ArrayList&lt;Future&lt;MyJob&gt;&gt;(); // submit the initial jobs for (int i = 0; i &lt; numThreads; i++) { MyJob myJob = getNextBestJob(); futures.add(threadPool.submit(myJob, myJob)); } // the list is growing so we use for i for (int i = 0; i &lt; futures.size(); i++) { // wait for a job to finish MyJob myJob = futures.get(i); // process the job somehow // get the next best job now that the previous one finished MyJob nextJob = getNextBestJob(); if (nextJob != null) { // submit the next job unless we are done futures.add(threadPool.submit(myJob, myJob)); } } </code></pre> <p>However, I don't quite understand how the thread count would change however. If you edit your question with some more details I can tweak my response.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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