Hi all,

in one of my apps users are working with a lot of entities (~10000) quite frequently. The entire user session runs inside one UoW. As the UoW caches all entities it ever reads this leads to memory problems. Loading 10000 entities allocates ~100MB. This is ok for a short period while the user actually works with the entities - but the UoW cache holds the entire 100MB for the whole user session.

So I tried a weak/soft reference cache in UnitOfWorkInstance. This seems to work but there are some open questions/problems:

- The store and some concerns need to use weak/soft references too. Ok did it.

- If the store uses soft references, then it needs a way to get notified if an entity has been modified, so that it can make a strong reference to it (in order to not loose modified state). Currently I dont see a way to let the store know (without introducing a new method).

- My simple approach introduces a race condition that may lead to lost update in the worst case. Situation: A reads entity and presents it in the UI. Then GC reclaims the entity. Then B reads/modifies/commits this entity. Then A reads the entity again (together with new timestamp from B), modifies something that B has modified and writes back to the store loosing changes from B.

- Is an UoW supposed to be accessed by concurrent threads? If yes then check/set entities from cache code in UnitOfWorkInstance needs to be synchronized with the cache.

Any ideas? And/or are there any other problems/pitfalls I'm missing so far?

Thanks,
Falko
--
Falko Bräutigam
http://polymap.org

_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to