0

According to this answer ChronicleMap's entrySet().iterator() will dump all objects in memory.

I do not want to load all objects in memory and filter the entire map in memory - that defeats the purpose of chroniclemap.

So now, Given a chronicle map type <LongValue, Pojo>, and keys ranging from 0-1000 how would I -

  1. fetch keys ranging >= 500
  2. delete keys ranging <500
NRJ
  • 1,064
  • 3
  • 15
  • 32

1 Answers1

1

You can use a ThreadLocal to cache this value or create as needed.

// cache as desired
LongValue key = Values.newHeapInstance(LongValue.class);

To fetch many values without creating garbage

// cached value for a Pojo
Pojo pojo = acquirePojo();

for (int i = 500; i < max; i++) {
    key.setValue(i);
    Pojo p2 = map.getUsing(key, pojo);
}

This will create little or no garbage to remove entries

for (int i = 0; i < 500 ; i++) {
    key.setValue(i);
    // assume map was built with removeReturnsNull(true)
    map.remove(key);
}
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130