public void flush(){
    System.err.println("Flushing the DB...");
    for(;;){
      try{
        synchronized(this.queue){
          this.queue.wait();
          System.err.println("Flushed");
          return;
        }
      }catch(InterruptedException e){
        //if we are interrupted go back to waiting some more
        //This is not a problem
      }
    }
  }