Code example for LinkedBlockingDeque

0
    private final LinkedBlockingDeque<Double> latencies;
    private static final double SENTINEL_COMPARE = 0.0001; // arbitrary; as long as it is the same across hosts it doesn't matter
 
    AdaptiveLatencyTracker(int size)
    { 
        latencies = new LinkedBlockingDeque<Double>(size);
    } 
 
    public void add(double i)
    { 
        if (!latencies.offer(i))
        { 
            latencies.remove();
            latencies.offer(i);
        } 
    } 
 
    public void clear() 
    { 
        latencies.clear();
    }