Pausing program until next startup

69 Views Asked by At

I have a program which bruteforces an AES256 encryption, how would I pause the program when the computer goes into shutdown/or reboot and continue at the same point until the next boot of the system?

A sort of hibernate of the program.

2

There are 2 best solutions below

2
On BEST ANSWER

You asked three things here.

1- How can I check when the OS goes reboot/shutdown

Solution: You can make an empty invisible window, and add WindowListener to it. It will receive windowClosing event on windows.

You can find an example HERE

2- How can I save the state of my BruteForce process and pause to start again when system goes up.

Solution: Here is easy, you must serialize. These will save the state of your class/classes to deserialize when system goes UP again. You can study HERE

3- How know when startup the programm again when OS goes UP?

Solution: You can put your program in initialization process of your OS. When it starts, you check if there is anything to deserialize and do it, restoring the process of the BruteForce.

4
On

I would agree with part 2 and 3 of @Thufir's answer, but regarding part 1 it assumes that you are running a GUI.

Instead of this I would add a shutdown hook into the JVM and write the state of my program at that point. You can do this using the following:

Runtime.getRuntime().addShutdownHook(new Thread() {
   public void run() {
       // your serialization code goes here
   }
});