Java 崩溃的 Windows
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2024040/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java Crashing Windows
提问by twolfe18
I have been developing a Java application using J2EE and a Derby database. My boss does most of the testing and I do most of the coding, but he has come to me with a strange problem. He claims that occasionally the Java application "crashes his computer".
我一直在使用 J2EE 和 Derby 数据库开发 Java 应用程序。我的老板做了大部分测试,我做了大部分编码,但他带着一个奇怪的问题来找我。他声称 Java 应用程序偶尔会“崩溃他的计算机”。
To mention a few details, first let me say that I am currently working remotely, so I can't be around when these "crashes" happen. Second, I use OS X 10.6 and he uses Windows XP (SP3 I believe). The Java application in question does not use any JNI or anything weird except for an embedded Derby database. Lastly, he said it freezes everything in Windows (his mouse doesn't even move) -- it doesn't show up in the console like an uncaught exception would.
先说几个细节,我先说我目前在远程工作,所以当这些“崩溃”发生时我不能在身边。其次,我使用 OS X 10.6,他使用 Windows XP(我相信是 SP3)。除了嵌入的 Derby 数据库之外,所讨论的 Java 应用程序不使用任何 JNI 或任何奇怪的东西。最后,他说它会冻结 Windows 中的所有内容(他的鼠标甚至不动)——它不会像未捕获的异常那样显示在控制台中。
So, is it possible that my Java program is crashing his computer? I didn't think that Java code could have any system-wide effects outside of the JVM. Is this something that could possibly be the fault of my program, or should I just ignore it and attribute it to some problem with his computer?
那么,我的 Java 程序是否有可能导致他的计算机崩溃?我不认为 Java 代码会在 JVM 之外产生任何系统范围的影响。这是否可能是我的程序的错误,还是我应该忽略它并将其归因于他的计算机的某些问题?
回答by rsp
For a Java application to crash the OS it runs on, there must be a bug in the JVM. That said there are situations that can give the same impression:
对于 Java 应用程序使其运行的操作系统崩溃,JVM 中必须存在错误。也就是说,有些情况会给人同样的印象:
- the Java application can grow its heap far enough that the OS starts to swap and other applications appear to slow down to a halt
- the Java application can grab all CPU by one or more threads in a tight busy loop
- Java 应用程序可以将其堆增长到足以使操作系统开始交换并且其他应用程序似乎变慢以至停止
- Java 应用程序可以通过一个或多个线程在一个紧凑的繁忙循环中占用所有 CPU
If you can setup your testers' machine so that a heap dump can be triggered when the problem occurs, you can analyse that dump remotely. For instance with IBM's Java heap analyzerfound on alphaworks.
如果您可以设置测试人员的机器,以便在问题发生时触发堆转储,您就可以远程分析该转储。例如,在 alphaworks 上使用 IBM 的Java 堆分析器。
回答by TofuBeer
There were cases before of crashes under windows on IBM Thinkpads (and other machines I am sure) due to a bad graphics driver. I'd suggest doing the usual thing of making sure the drivers are up to date just to be on the safe side.
由于图形驱动程序错误,IBM Thinkpad(以及我确定的其他机器)上的 Windows 下曾发生过崩溃的情况。我建议做通常的事情,确保驱动程序是最新的,只是为了安全起见。
While your code may not use JNI directly a lot of what happens under the hood can (anything that integrates with the underlying OS essentially). Which means drivers can be a big problem.
虽然您的代码可能不会直接使用 JNI,但在幕后发生的很多事情都可以(本质上与底层操作系统集成的任何东西)。这意味着驱动程序可能是一个大问题。
The other thing would to be sure that the most recent version of the Java is being used (if 1.6_17 isn't possible at last the latest version of the version of Java being used).
另一件事是确保正在使用最新版本的 Java(如果 1.6_17 最终不可能使用最新版本的 Java 版本)。
One other thing that has fixed random crashes for me is to re-seat the memory (unplug it and plug it back in).
为我修复随机崩溃的另一件事是重新安装内存(拔下它并重新插入)。
回答by bobince
he said it freezes everything in Windows (his mouse doesn't even move)
他说它会冻结 Windows 中的所有内容(他的鼠标甚至不动)
A user-mode application?—?whether Java or otherwise?—?can't do that against a modern OS like WinNT.
用户模式应用程序?——?无论是 Java 还是其他?——?不能在像 WinNT 这样的现代操作系统上做到这一点。
He either has a hardware problem, or a bad driver.
他要么有硬件问题,要么是驱动程序不好。
回答by Aaron Esau
To crash the entire computer, try this:
要使整个计算机崩溃,请尝试以下操作:
public void crashComputer() {
while(true)
new Thread(new Runnable() {
@Override
public void run() {
while(true) {
crashComputer();
}
}
}).start();
}
public void crashJVM() {
while(true)
crashJVM();
}
The crashComputer function takes about 2 seconds to crash the entire computer. You can stop it from crashing by holding power button.
crashComputer 函数大约需要 2 秒才能使整个计算机崩溃。您可以通过按住电源按钮阻止它崩溃。
The crashJVM function crashed only the JVM by overloading the stack, causing a stack overflow (That's where the name of this website comes from).
crashJVM 函数通过重载堆栈使JVM 崩溃,导致堆栈溢出(这就是本网站名称的由来)。
WARNING:Use at your own risk. This will not damage your computer, but I'm not taking the blame if you forget to click save on a document or something.
警告:使用风险自负。这不会损坏您的计算机,但如果您忘记单击保存文档或其他内容,我不会承担任何责任。
回答by Bill
Also check the page file space on the client (Windows/XP) system.
还要检查客户端(Windows/XP)系统上的页面文件空间。
回答by RalphChapin
Point one:On my XP, SP3 system, when any program runs full tilt, it almost locks up the computer. When my anti-virus program checks for updates, everything else stops for all practical purposes, and it uses very little CPU (seems to be writing to disk all the time). My own infinite loops, using 100% CPU, have a similar effect. (Why the task manager does not get priority over a user program with "normal" priority I do not know.)
第一点:在我的XP、SP3系统上,当任何程序全速运行时,它几乎锁定了计算机。当我的防病毒程序检查更新时,出于所有实际目的,其他一切都会停止,并且它使用的 CPU 很少(似乎一直在写入磁盘)。我自己的无限循环,使用 100% CPU,也有类似的效果。(为什么任务管理器没有优先于具有“正常”优先级的用户程序,我不知道。)
Point two:On any computer I've ever used, heavy paging will bring a program to an almost complete stop.
第二点:在我使用过的任何计算机上,大量分页都会使程序几乎完全停止。
So start with an XP computer with 512Mb of real memory and 2000Mb of virtual memory. Write a Java program with 1400Mb worth of arrays and other data structures. Put in a loop that repeats several billion times and reads or writes to each byte in that 1400Mb on each execution. This program will not finish until long after the universe collapses in on itself. The computer will do nothing. I have not tried this and I do not intend to, but I will bet anything even the mouse won't move. Depending on the make of the computer, the only fix may be pulling the power plug out of the wall socket. (Note that technically, the computer has not crashed. Indeed, it is working just fine. But you are going to need to be patient. Move the mouse the day before you plan to click.)
因此,从具有 512Mb 实内存和 2000Mb 虚拟内存的 XP 计算机开始。用 1400Mb 的数组和其他数据结构编写一个 Java 程序。放入一个重复数十亿次的循环,并在每次执行时读取或写入 1400Mb 中的每个字节。这个程序要到宇宙自行坍缩很久之后才能完成。电脑什么都不做。我没有尝试过,也不打算尝试,但我敢打赌,即使鼠标不动。根据计算机的品牌,唯一的解决方法可能是将电源插头从墙上的插座中拔出。(请注意,从技术上讲,计算机并没有崩溃。确实,它工作得很好。但是您需要耐心等待。在您计划单击的前一天移动鼠标。)
The moral of this story is to avoid both XP and virtual memory, but if you have to deal with either, be aware of these problems.
这个故事的寓意是避免同时使用 XP 和虚拟内存,但是如果您必须处理任何一个,请注意这些问题。