Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It depends on the collection. If no structural change is happening during the read - you can read it concurrently, it is fine. Most collections do NOT change the structure for read or iteration only, so it is OK, but make sure to read the documenation of the collection you are using before doing so.</p> <p>For example, <a href="http://docs.oracle.com/javase/6/docs/api/java/util/HashSet.html" rel="nofollow">HashSet javadocs</a>:</p> <blockquote> <p>Note that this implementation is not synchronized. If multiple threads access a hash set concurrently, and at least one of the threads modifies the set, it must be synchronized externally.</p> </blockquote> <p>It implies reading from two threads concurrently is just fine, as long as there is no write.</p> <hr> <p>One way to do it is split the data, and let each thread read <code>collection.size()/ numberOfThreads</code> elements. <br>thread #i will read from <code>collection.size()/numThreads * i</code> to <code>collection.size()/numThreads * (i+1)</code></p> <p>(Note special care will be needed to guarantee the last elements are not missed, it can be done by setting the last thread frpm <code>collection.size()/numThreads * i</code> to <code>collection.size()</code>, but it might make the last thread do much more work, and will make you wait for struggling threads).</p> <p>Another option is using task queue of intervals, and each thread will read elements while the queue is not empty, and reading the elements in the given intervals. The queue will have to be synchronized because it is modified by multiple threads concurrently.</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. 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