Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When you use an <code>ExecutorService</code> you submit <code>Runnable</code> jobs to a thread-pool that are run in turn by the threads in the pool. You could do one of the following:</p> <ol> <li><p>Have each <code>Runnable</code> sit in a loop, dequeueing from a <code>BlockingQueue</code> in a loop to process each packet. That might be easier than all of them synchronizing around your buffer object. Something like:</p> <pre><code>public void run() { while (!shutdown) { packet = packetQueue.take(); processPacket(packet); } } </code></pre></li> <li><p>Alternatively, you can submit each packet to the thread-pool as a job itself although that might increase your object load. You could process each packet, extract the payload, and create a <code>Runnable</code> wrapper around the payload with the <code>run()</code> method which processes the payload. The contents of the <code>Runnable</code> class would be something like:</p> <pre><code>Payload payload; public void run() { // process packet here processPayload(payload); } </code></pre></li> </ol> <p>With both mechanisms, I'd choose a fixed thread number that best matches your number of processors and the nature of the processing task. The below example uses the number of processors but you might want to take a couple off for GC or other tasks. You might want to put more on in case the processing blocks on other IO. Only performance testing will tell you what the optimal value is there.</p> <pre><code>// start a pool that uses the number of threads that there are processors ExecutorService threadPool = Executors.newFixedThreadPool( Runtime.getRuntime().availableProcessors()); </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. 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