简体   繁体   English

当您关闭电源时,Java 程序会发生什么?

[英]What happens to a Java program when you turn the power off?

What happens within a Java application running locally on a PC when the power is switched off?(Plug pulled from wall).当电源关闭时,在 PC 上本地运行的 Java 应用程序会发生什么?(从墙上拔下插头)。

Does Java have a way of handling an event like this or is it simply wiped from memory as soon as the power is killed? Java 有没有办法处理这样的事件,还是只是在断电后立即从内存中擦除?

Edit: To be a bit more clear, I'm wondering if Java as any way of safely exiting an application in the last moments of an unexpected shutdown.编辑:更清楚一点,我想知道 Java 是否可以作为在意外关闭的最后时刻安全退出应用程序的任何方式。

Java programs (like all programs) require a CPU and memory to operate instructions. Java 程序(与所有程序一样)需要 CPU 和内存来操作指令。 Both elements are complex electrical circuits, they cannot work without electricity.这两个元件都是复杂的电路,没有电就不能工作。

The only thing you can do to persist the state of your application, is to write information regarding that state to disc.要保持应用程序的状态,您唯一可以做的就是将有关该状态的信息写入磁盘。 The Google File System uses this method to ensure not too much information is lost if one of their (usually inexpensive machines) goes down. 谷歌文件系统使用这种方法来确保在他们的一台(通常是便宜的机器)出现故障时不会丢失太多信息。

Short of this.少了这个。 No there is no way Java can handle a power out.不,Java 无法处理断电。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java程序启动时会发生什么? - What happens when java program starts? 在Java中,如果您的方法具有未指定的可见性关键字,会发生什么? - In Java, what happens when you have a method with an unspecified visibility keyword? 当你在java中将一个数组分配给另一个数组时会发生什么? - What happens when you assign an array to another array in java? 如果编译一个空的Java文件会怎样? - What happens if you compile an empty java file? 操作系统(linux)如何杀死Java程序? 当我硬杀死一个Java进程时,jvm会怎样? - how operating system(linux) kills java program ? What happens to the jvm when I hard kill a java process? 如何关闭带有Java代码的程序? - How do I turn off a program with a java code? 程序登录到控制台时会发生什么? - What happens when a program logs to the console? Spring 框架:当您将 Java bean 注入另一个 Java bean 时会发生什么,但它们具有不同的范围 - Spring framework: what happens when you inject a Java bean into another Java bean but they have different scopes 如何从Java应用程序中打开和关闭监视器? - How do you turn on and off a monitor from within a Java application? 覆盖布尔值时会发生什么? - What happens when you overwrite a Boolean value?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM