Search code examples
javapriority-queue

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? I.e. "notify me when the level reaches 500 elements"?


Solution

  • 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.