Java blocking queue containing only unique elements

后端 未结 5 1190
长发绾君心
长发绾君心 2020-12-11 15:45

sort of like a \"blocking set\". How can I implement a blocking queue where adding a member that is already in the set is ignored?

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-11 16:02

    class BlockingSet extends ArrayBlockingQueue {
       /*Retain all other methods except put*/
       public void put(E o) throws InterruptedException {
          if (!this.contains(o)){
             super.put(o);
          }
       }
    }
    

提交回复
热议问题