Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So, if I correctly understand your problem, you have one thread to fetch data, and several threads to analyse the fetched data. Your problem is that the threads are not correctly synchronized to run together and take full advantage of the processor.</p> <p>You have a tipical producer-consumer problem with a single producer and several consumers. I advise you to remake your code a bit to have, instead, several independent consumer threads that are always waiting for resources to be available and only then running. This way you guarantee the maximum processor use.</p> <p>Consumer thread:</p> <pre><code>while (!terminate) { synchronized (Producer.getLockObject()) { try { //sleep (no processing at all) Producer.getLockObject().wait(); } catch (Exceptions..) } MyObject p = Producer.getObjectFromQueue(); //this function should be synchronized //Analyse fetched data, and submit it to somewhere... } </code></pre> <p>Producer thread:</p> <pre><code>while (!terminate) { MyObject newData = fetchData(); //fetch data from remote location addDataToQueueu(newData); //this should also be synchronized synchronized (getLockObject()) { //wake up one thread to deal with the data getLockObject().notify(); } } </code></pre> <p>You see that this way, your threads are always performing useful work or sleeping. This is just draft code to exemplify. See more explanation here: <a href="http://www.javamex.com/tutorials/wait_notify_how_to.shtml" rel="nofollow">http://www.javamex.com/tutorials/wait_notify_how_to.shtml</a> and here: <a href="http://www.java-samples.com/showtutorial.php?tutorialid=306" rel="nofollow">http://www.java-samples.com/showtutorial.php?tutorialid=306</a></p>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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