简体   繁体   中英

Priority queue with level-based notification in Java

Is there a kind of PriorityBlockingQueue in Java that allows waiting (like the take() method does) for a certain level of elements instead of one element? Ie "notify me when the level reaches 500 elements"?

Is there a kind of BlockingPriorityQueue in Java that allows waiting (like the take() method does) for a certain level of elements instead of one element?

No . There is a PriorityBlockingQueue

No you don't have maybe you can extend PriorityBlockingQueue for your need. take() can return once you have more than 500 elements.

private volatile size;

public synchronized void take(){
      while(size<500){
        ........
        .........
      }
}

just pseudocode.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM