queue的增强版
public class EnhancedQueue<E> extends LinkedBlockingQueue<E>{
private Counter pendings;
private Meter inQueueMeter;
private Meter deQueueMeter;
private String name;
public EnhancedQueue(MetricRegistry metricRegistry,String name){
this.name = name;
this.pendings = metricRegistry.counter(MetricRegistry.name(EnhancedQueue.class + name, "pendings"));
this.inQueueMeter = metricRegistry.meter(MetricRegistry.name(EnhancedQueue.class + name,"in-queue","tps"));
this.deQueueMeter = metricRegistry.meter(MetricRegistry.name(EnhancedQueue.class + name,"de-queue","tps"));
}
@Override
public E take() throws InterruptedException {
E element = super.take();
pendings.dec();
deQueueMeter.mark();
return element;
}
@Override
public void put(E e) throws InterruptedException {
super.put(e);
pendings.inc();
inQueueMeter.mark();
}
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。