Fastest way to serialize relatively simple Java POJOs?
I need to write millions of Java POJOs to d开发者_Go百科isk, and read them from disk, and I need to do it fast.
I would prefer to avoid having to define a separate template file as I believe is required with Thrift and Google Protocol Buffers. Rather, it would be preferable if the Java class itself was the authoritative specification for the object (as with Java Serialization, Gson, and other serialization protocols). I realize that there may be a bit of a performance hit here, but its ok provided its not an order of magnitude slower.
The classes to be serialized consist of several simple long and String fields, and a single Map (where the values in this map are all either Numbers or Strings).
Can anyone suggest some libraries that I should look at for this?
Test first with Java serialization, and see if it's fast enough. It's built in, and is competent enough to handle graphs and multiple versions.
There is no reason to look for alternatives until you know you need it.
Edit: You will need to reset() the ObjectStream, in order to not fill the lookup table with references to already written objects. If you are writing relatively independent objects, that is probably not a problem to do a reset after every "top" object, but if you have complex relations in your data, i suggest that you try JPA or something else.
精彩评论