title: In Java, what's the best way to keep top 100 items in a multi-threaded program?
body: <p>I'm running Java 8, my application is a multithreaded search program. It has hundreds of threads; each does some calculation and gets a result with a score, and all the threads put their results into a vector. But I don't want to save all the results, because there are millions of them, too many, and I'm only interested in the results with a score [0 - 100] of 80 or more, and I only want to collect the top 100 of the results, so now in my app I have a vector of size 100. If there is less then 100 item in it, just add to it, when there is 100 item to it, do the following :</p>
  
  <pre><code>myVector.set(99,result);
  Collestions.sort(myVector);
  </code></pre>
  
  <p>So the last item always has the least score and gets replaced if a new item has higher score.
  I wonder if this approach is the best, and is it the fastest? Any other better ones?</p>