I'm reaching out to the community here to understand if there is a way to store many objects in a Java map structure (> 500K). I know at some point my application will exceed its memory footprint if I use the Java Collections API and I'm looking for other solutions (outside of distributed caching). My intention is to store something to the effect of Map<String, List<String>>.
Requirements:
Does anyone know of such a library I can utilize that can achieve this or has anyone ever come across a solution in which they were required to load many objects in memory in Java? I'd be very interested in hearing your feedback.
Thanks.
Saving object in java can be accomplished in a number of ways, the most prominent of which is to serialize the object - saving it to a file and reading the object using an ObjectOutputStream and ObjectInputStream, respectively. Serialization is a fantastic advantage to using java.
Yes, since objects are also considered as datatypes (reference) in Java, you can create an array of the type of a particular class and, populate it with instances of that class.
In Java, we can create more than one object of the same class, the syntax of the object creation will be the same as we followed in the previous example: This is how you can create multiple objects of a class.
EhCache would be perfect for this. At its most basic, it offers a key-value map, with optional overflow to disk, and optional persistence over JVM restarts. It will keep elements in memory that are most frequently used.
I'm with skaffman. In addition to the overflow to disk EhCache offers you to place the cache in-process but off-heap. If your cache is really big, this may have a very positive impact on performance since it reduces stress on the GC.
This specific feature however must be payed for, but otherwise EhCache is free.
Instead of EhCache, there are a couple of other caches in Java that offer similar or sometimes even more advanced options like Infinispan or OsCache.
Have you considered a read-only database, such as a java cdb: http://www.strangegizmo.com/products/sg-cdb/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With