Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could use a <code>NavigableMap</code> which allows you to query a range of numbers (head, tail). A thread safe implementation is <code>ConcurrentSkipListMap</code>.</p> <p>In particular look the the methods <code>NavigableMap&lt;K,V&gt; headMap(K toKey, boolean inclusive)</code>, <code>NavigableMap&lt;K,V&gt; tailMap(K fromKey, boolean inclusive)</code> and <code>SortedMap&lt;K,V&gt; subMap(K fromKey, K toKey)</code></p> <p>Example </p> <pre><code>//your existing concurrent map changed to concurrent navigable map NavigableMap&lt;Long, Long&gt; throughputCounter = new ConcurrentSkipListMap&lt;Long, Long&gt;(); // this prints for inclusive values - 1 and 20 are both included System.out.println("How many calls(X number) came back in between 1 and 20 ms:" + calcThroughput(throughputCounter.subMap(1L, true, 20L, true))); System.out.println("How many calls(X number) came back in between 20 and 40 ms:" + calcThroughput(throughputCounter.subMap(20L, true, 40L, true))); System.out.println("How many calls(X number) came back in between 40 and 60 ms:" + calcThroughput(throughputCounter.subMap(40L, true, 60L, true))); System.out.println("How many calls(X number) came back in between 60 and 80 ms:" + calcThroughput(throughputCounter.subMap(60L, true, 80L, true))); System.out.println("How many calls(X number) came back in between 80 and 100 ms:" + calcThroughput(throughputCounter.subMap(80L, true, 100L, true))); System.out.println("How many calls(X number) came back in after 100 ms:" + calcThroughput(throughputCounter.tailMap(100L))); private Long calcThroughput(NavigableMap&lt;Long, Long&gt; subMap) { Long sumOfARange = new Long(0); for (Long value : subMap.values()) { sumOfARange += value; } return sumOfARange; } </code></pre>
 

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