Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Collection which pages to disk when it gets full?

A colleague mentioned that he heard about a lightweight collection which would automatically page out to disk when it's contents got too full - but he couldn't remember the name. I would imagine it looks something like this:

PagingCollection<Serializable> pagingCollection = new PagingArrayList<>();
pagingCollection.setMaxSizeInMemory(500);
for (int x = 0; x < 1000; x++) { pagingcollection.add("x="+x); }

Which would then push x=0 to x=500 to disk. The key would be being able to iterate over it without loading the whole thing into memory..

This is for a thick client with low amounts of memory.

Does anyone know of it (or something similar)?

like image 982
Robert Wilson Avatar asked May 05 '10 14:05

Robert Wilson


2 Answers

Well, the only tools I know that has this kind of features are the prevalence systems : prevayler and space4j (the later seems to no more have a dedicated website, but to be still available ... on Sourceforge). Although their interface will seems weird to you at first, they are however quite simple to use and offer a convenient feature set.

like image 61
Riduidel Avatar answered Oct 16 '22 14:10

Riduidel


MapDB (mapdb.org) is a library that supports disk based collections: Sets, Queues and Maps.

You can choose yourself when to persist it do disk or just persist on every update.

It also supports caching so all your items will be on disk but some cached in memory.

like image 24
Andrejs Avatar answered Oct 16 '22 14:10

Andrejs