0

I have an object that occupies approximately 15GB in my java app's heap, and I need to keep it persistent between JVM restarts. I use ObjectOutputStream's writeObject method to write it to file on the disk every time interval. Since the writing process is very long (a few minutes) and causes some GC issues, I would like to split the object somehow to persist each part separately to a different file and not in a single action to a single file. Is there a way to do this (and of course to retrieve it back from the files when I need it)?

        FileOutputStream fos = null;
        GZIPOutputStream gos = null;
        ObjectOutputStream oos = null;
        try {
            fos = new FileOutputStream("some_path");
            gos = new GZIPOutputStream(fos);
            oos = new ObjectOutputStream(gos);
            oos.writeObject(myLargeObject);
            oos.flush();
            gos.close();
            fos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
Shai Givati
  • 1,106
  • 1
  • 10
  • 24

1 Answers1

0

You may want to take a look at this answer. The reverse process of recomposing the split files is nothing more than reading from each individual file and appending to a "master" one.

Niko
  • 616
  • 4
  • 20