Java Serialization for long-ish-term storage

I have an application that uses a database of about 15,000 Java objects, which I have to read every time the application starts. Originally I’ve been using JSON to store the data, but that has a few issues, mostly that it’s slow (it can take 8-10 seconds to read all the objects on my lower-end machine) and also, it’s very common for the objects in my database to have fields that point to the same object. Java serialization handles this by using references to the same object, whereas with JSON, I just have to write the state of each object and then intern them during reading. This also bloats the file size.

The contents of this database will be updated fairly infrequently (maybe about once a month or so). I’ve heard from pretty much every source that Java serialization is always a poor choice for long-term storage, and I understand why. Given these conditions, however, is there a good reason not to use Java serialization here?

4

While you do not anticipate changing the nature of your objects now very much – needs change over time.

I would highly suggest you consider using protobuf or Apache Thrift or a similar design instead of relying on default Java serialization.

Their advantages include strong support for avoiding impact during minor version changes, significantly better serialization and deserialization speed and smaller footprint of objects.

When I do this, typically I include the message version as a field on the object. This allows me to implement version-to-version changes during the serialization by wrapping that method, if that need should arise in the future.

2

I wouldn’t store the serialized objects for long term.
As the others already stated: When you change a litte bit on your classes, (maybe you don’t even notice it) maybe you can’t load your data. It will be hell to fix it.

I’m not sure, why you need all the data in the memory. Is it, because it is used everytime and everywhere in your software (master data)? Looks like a “Yes”

What I would do:
I would store the data in a inmemory-database (hsqldb,…)
dump the file and provide the file on the machine
After the startup I would load the file (quite fast) and then use it like a “normal” database.

You can do this also with your serialized objects. But I wouldn’t see a sense any more. The “normal” database can be cached and will be extremly fast. So query the object.

I agree with the comments to the effect that Java serialization is unstable and difficult to maintain as your classes change. I recommend writing your own read/write routine to a format that is understandable by humans and manually editable (if need be). You can
probably package this as static data that will be digested into your runtime data
structure mostly by the compiler.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật