I have a Queue
which I want to convert into long[]
and pass it to my method which calculate percentiles.
private final ConcurrentLinkedQueue<Long> holder = new ConcurrentLinkedQueue<>();
I am using ConcurrentLinkedQueue
because I am inserting latencies which are in milliseconds from multithread application into my above holder
queue so I wanted to be thread safe.
Now my question is how can I convert holder
queue into long[]
long array so that I can pass it to my below method? Is there any way to do that?
public static long[] percentiles(long[] latencies, double... percentiles) {
Arrays.sort(latencies, 0, latencies.length);
long[] values = new long[percentiles.length];
for (int i = 0; i < percentiles.length; i++) {
int index = (int) (percentiles[i] * latencies.length);
values[i] = latencies[index];
}
return values;
}