如何制作故障安全程序 [英] how to make a failsafe program

查看:66
本文介绍了如何制作故障安全程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人
我想制作一个故障保护程序,现在我有一个程序,可以进行多次测量,并且包含很多线程,现在以防万一我不能使用UPS,我希望我的程序在突然断电后能够恢复其最后的状态.如果没有关闭电源,Windows休眠之类的东西

是序列化还是有更简单的健壮解决方案


谢谢bye

dear all
i want to make a failsafe program , now i have a program which makes many measurements and it contains many threads , now in case i can''t use an UPS , i want my program to restore its last state after a sudden power off as if no power off was happened umm something like Windows hibernate

is it serialization or there is more easier robust solutions


thanks bye

推荐答案

如果您不使用UPS,那么灾难性的电源故障将是一个真正的问题.可以这么说,唯一可以从上次中断的地方接机"的方法是每x秒左右保存一次应用程序状态.您执行此操作的频率取决于您需要保存的数据量以及对应用程序性能的影响.您在这里的想法问题可能是对Windows休眠实际功能的误解. Windows休眠不会关闭计算机,它只是减少了正在使用的资源,而是保留了内存等,这就是为什么从休眠状态返回时一切都保留在原来的位置的原因.完全掉电是完全不同的.
If you aren''t using a UPS, then a catastrophic power failure is a real problem. The only way you can "pick up where you left off", so to speak, is to save your application state every x number of seconds or so. How often you can do this will depend on the amount of data you need to save down and the impact this will have on your application performance. The issue with your thinking here may be a misunderstanding of what Windows hibernate actually does. Windows hibernate does not turn off the computer, it simply reduces the resources being used, but memory and such is maintained which is why everything is where you left it when you return from hibernation. A full power down is completely different.


那根本不容易.

Windows休眠与您尝试执行的操作不同,它将休眠状态的当前内容保存到HDD中,并在唤醒时重新加载-因为它在停止时的确切位置再次开始.

你不能那样做.像这样保存状态需要电源-其中很多-因为它必须运行HDD并写掉信息.当电源出现故障时,这绝对是您最后一次要写入磁盘的时间,因为写入操作很可能会损坏磁盘的其余部分.这就是为什么现代硬盘具有电源故障检测器,并在发生故障时停止写入并将磁头停在安全的位置的原因-防止磁头降落在磁盘表面上并对其造成物理损坏.

您可以执行类似的操作(许多程序可以执行),方法是定期保存应用程序的状态,以便在出现问题时可以恢复到最新状态.不过要注意两件事:
1)不要太频繁地存钱.这样只会使HDD的访问持续下去,并担心人们以及潜在的利益;只会缩短HDD的使用寿命.
2)保留多份副本,并在其中进行良好的错误检查,以便在编写时如果电源出现故障,可以检测到该副本并改用以前的版本.

我自己购买一台UPS并用完它!
That is not easy, at all.

Windows hibernate is different to what you are trying to do, it saves the current memory content to the HDD and reloads it when it wakes up - as it starts again at the exact point at which it left off.

You can''t do that. Saving status like that needs power - and lots of it - as it has to run the HDD and write in0formation away. When the power fails, that is absolutely the last time you want to be writing to the disk, as it is quite possible that the act of writing away will corrupt the rest of the disk. That is why modern HDD''s have a power fail detector, and stop writing and park the heads in a safe location when it occurs - to prevent the heads landing on the disk surface and physically damaging it.

You can do something similar - many programs do - by saving your app''s status at regular intervals so that you can restore to a almost-up-to-date position in the event of a problem. Two things to watch for though:
1) Don''t save too often. That will just keep the HDD access going, and worry people, as well as potential;;ly shortening tyhe life of the HDD.
2) Keep several copies, and make your you put good error checking in them, so that if the power fails while you are writing, you can detect it and use the previous version instead.

I would buy a UPS and be done with it, myself!


作为其他信息(以获取有关捕获应用程序状态的指导),您可以查看http://en.wikipedia.org/wiki/Memento_pattern [
As additional information (to have a guidance on capturing your application state) you may have a look at the http://en.wikipedia.org/wiki/Memento_pattern[^].


这篇关于如何制作故障安全程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆