Java method for saving the current state of a program

Is it possible to save the current state of a java program and then reload it? The program is quite complicated. I just need to save the current state to a file and then reload it. Could you refer to the java library or place to find out more about this.

+6
source share
2 answers

There is no real way to "save the state of the entire JVM" as such.

But you can encapsulate the corresponding state of your application into one or more objects, and then serialize these objects. This sounds more complicated than it really is because, most likely, the state of your application is already (mostly) enclosed in some objects.

This serialization tutorial provides more information, see this page for details .

+10
source

The "state" of a java program is a complex beast. This will include the full heap, the execution point of all threads, the values โ€‹โ€‹of local variables ...

Most likely, you just want to save the state of some , and then load it into a new program. You can use classes in java.io to write state to files and then read them again.

http://download.oracle.com/javase/7/docs/api/java/io/package-summary.html

+3
source

Source: https://habr.com/ru/post/900032/


All Articles