我想让我的应用程序启动时间大大加快。
我相信,如果我可以将应用程序的整个状态存储在运行 java 虚拟机的进程的内存空间中,那么我也应该能够创建一个新的 java 进程并将其内存内容替换为保存的状态在图像文件中。
我的理论是,如果我这样做,我可以快几秒钟启动我的应用程序,它会尽可能快地读取文件并将其放入 jvm 的正确内存区域。
我想让我的应用程序启动时间大大加快。
我相信,如果我可以将应用程序的整个状态存储在运行 java 虚拟机的进程的内存空间中,那么我也应该能够创建一个新的 java 进程并将其内存内容替换为保存的状态在图像文件中。
我的理论是,如果我这样做,我可以快几秒钟启动我的应用程序,它会尽可能快地读取文件并将其放入 jvm 的正确内存区域。
You can use serialization to write the state of the application (beware of cycles in the object graph, though), and then deserialize it on startup, but that's not quite the same as creating an image of the JVM process. You'll still need to load the classes and instanciate some basic infrastructure to bootstrap the application, and you won't be in the same state memory- and JIT-wise. The JVM abstracts a lot of things from you, so you don't have access to "the right memory zone(s)".
Whether it will have a positive impact on the application's startup time really depends on where the state is initially loaded from and how much it costs to build, anyway.