Forums Register Login

Is There a Java Exception that Gets Thrown when a Computer Shuts Down?

+Pie Number of slices to send: Send
I have a Java program that has been converting a very large number from hexadecimal (55,732,656 digits) to its decimal equivalent. The only algorithm I know for doing that is O(n^2), so my program has been running for about four days, and it was only about 40% done an hour ago. A half hour ago something went wrong with my keyboard, and when I pressed a key, any key, nothing happened. I couldn't edit the Word file I was working on; I couldn't type a command or any input into any of my command windows; I couldn't do much of anything. So I restarted my computer. That fixed the problem with the unresponsive keyboard; now I can type and have what I type show up in the window I'm working on. But the downside is that I lost all four day's worth of calculation, translating my huge hexadecimal number into decimal.

Is there by any chance a Java exception that gets thrown when the computer starts to do a shutdown prior to a restart, that I could catch and handle by writing my intermediate data to disk, so that all my work on a program that is likely to last for ten or so days doesn't get lost? It'd be nice if I could write an exception handler into my code that keeps me from losing four days work like I just did.
1
+Pie Number of slices to send: Send
I don't know if this would work for you but for some long running problems I subdivide the problem into manageable pieces and write the partial results to a file(s). At the end I read back all the files and combine them into the final result. I write the program in such a way that if the program aborts it only has to pick up where it left off.
1
+Pie Number of slices to send: Send

If it is a forced shutdown, either via the kill signal, or hardware shutdown, then "no", there is no way to continue running -- in order to clean everything up.  If it is a termination signal, like a control-c, then "yes", you can add a shutdown hook. Take a look at the Runtime class regarding this.

Henry
1
+Pie Number of slices to send: Send
 

Carey Brown wrote:I don't know if this would work for you but for some long running problems I subdivide the problem into manageable pieces and write the partial results to a file(s). At the end I read back all the files and combine them into the final result. I write the program in such a way that if the program aborts it only has to pick up where it left off.


That's good advice, and I just implemented it in my code.
You didn't tell me he was so big. Unlike this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 344 times.
Similar Threads
Windows 8 sucks
"is not recognized as an internal or external command, operable program or batch file" error
when did you learn how to code and in what?
exception
keyboard log
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 23:09:57.