简体   繁体   中英

What is the quickest way to load a serialized hashmap in Java?

I have serialized a HashMap into a file using objectstream and fileoutputstream. It is a very huge HashMap with around 150 million entries. It takes a long time (~40 mins) to load when I read it back from the file.

I am using a FileOutputStream followed by ObjectOutputStream to serialize the object. Then, I am using the ObjectInputStream and FileInputStream to read the object.

Is there a recommended way to read a serialized HashMap so that it loads quickly from the file?

Using a BufferedInputStream should improve the performance:

ObjectInputStream in = 
    new ObjectInputStream(new BufferedInputStream(new FileInputStream(file)));

And of course, a BufferedOutputStream would also improve the performance of the serialization.

Using those buffered streams allow reading large chunks of bytes from the file system in one shot, instead of reading byte per byte. Read the documentation for more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM