title: Leveldb for Java: deleting while iterating
body: <p>I am running this test:</p>
  
  <pre><code>public class LeveldbTest {
  
  @Test
  public void test() throws IOException, InterruptedException {
      DBFactory factory = new Iq80DBFactory();
  
      Options opts = new Options();
      opts.cacheSize(4096);
      opts.compressionType(CompressionType.SNAPPY);
      opts.createIfMissing(true).writeBufferSize(4096);
      final DB db = factory.open(new File("target/leveldb"), opts);
      final AtomicLong counter = new AtomicLong();
  
      long start = System.currentTimeMillis();
      new Thread() {
          @Override
          public void run() {
              WriteOptions wo = new WriteOptions();
              wo.sync(true);
              while (true) {
                  String key = UUID.randomUUID().toString();
                  byte[] bytes = key.getBytes();
                  System.out.println("putting: " + key);
                  db.put(bytes, bytes, wo);
                  counter.incrementAndGet();
              }
          }
      }.start();
  
      new Thread() {
          @Override
          public void run() {
              WriteOptions wo = new WriteOptions();
              ReadOptions ro = new ReadOptions();
              wo.sync(true);
              while (true) {
                  DBIterator iterator = db.iterator(ro);
                  if (iterator.hasNext()) {
                      Entry&lt;byte[], byte[]&gt; next = iterator.next();
                      byte[] key = next.getKey();
                      System.out.println("deleting: " + new String(key));
                      db.delete(key, wo);
                      counter.incrementAndGet();
                      try {
                          iterator.close();
                      } catch (IOException e) {
                      }
                  }
              }
          }
      }.start();
  
      Thread.sleep(3000);
      System.out.println((double) counter.longValue() / (System.currentTimeMillis() - start));
  }
  }
  </code></pre>
  
  <p>I am expecting that keys will be delete from the queue but in the console only the one and the same key seems to be deleted:</p>
  
  <pre><code>putting: a1ad4662-18c3-4085-af9d-a451dc3279c0
  deleting: 004ef0c2-b278-42c6-9c85-4769d93d5b30 &lt;-
  putting: 6c4ee31d-2910-4870-acc5-962f9c40a573
  deleting: 004ef0c2-b278-42c6-9c85-4769d93d5b30 &lt;-
  deleting: 004ef0c2-b278-42c6-9c85-4769d93d5b30 &lt;-
  putting: 63e2e438-3849-46e3-9ea0-1165f9356efb
  deleting: 004ef0c2-b278-42c6-9c85-4769d93d5b30 &lt;-
  </code></pre>
  
  <p>Am I using the API wrongly?</p>