为什么我的 Java 应用程序在全屏模式下运行如此缓慢? (窗口时很好)
我正在开发一个旨在以全屏模式运行的 Java 程序。它使用大量定制的 Swing 组件和 Java2D 绘制的组件,这些组件需要每秒更新和重新绘制多次。它在我的动力不足的工作电脑上运行得相对良好。
但后来我在家里用功能更强大的电脑尝试了它。而且它的运行速度明显变慢。触发一个本应立即更新大约 20 个不同屏幕元素的事件,却导致了每个元素似乎至少需要四分之一秒才能重新绘制的效果。因此,每次屏幕更改需要 5 秒才能完成,而不是即时更改。
我想也许我尝试重画的次数太多或者以错误的方式。但在尝试了一些其他想法之后,我凭直觉让应用程序以窗口模式而不是全屏模式启动。随着这一改变,一切开始变得非常快速和顺利。
所以我想这里确实有两个问题:为什么全屏模式会导致这个问题?为什么它只在我更快的计算机上引起这个问题?我确实怀疑存在与操作系统相关的错误。我的工作计算机运行速度慢,是 Windows XP,而家用计算机是 Windows 7。我在其他线程中看到 Win7 上的 Aero 会导致 Java 速度问题,因此我尝试禁用它。这确实导致速度略有提高,但仍然不如我在窗口模式下运行时那么流畅。还有其他人在 Win7 上运行全屏 Java 应用程序时遇到性能问题吗?如果是这样,有解决办法吗?
I'm working on a Java program that is intended to run in full-screen mode. It uses numerous of customized Swing components and Java2D-drawn components that need to be updated and repainted several times a second. And it was working relatively fine on my underpowered work PC.
But then I tried it out at home on my much more powerful PC. And it ran noticeably slower. Triggering an event that should have instantly updated about 20 different screen elements instead caused an effect where each element seemed to take at least a quarter second each to repaint itself. So instead of instantaneous changes it was taking 5 seconds to complete each screen change.
I thought that maybe I was trying to repaint too often or in the wrong manner. But after experimenting a bit with other ideas, on a hunch I let the application start up in a windowed mode instead of in full-screen mode. And with that one change, everything started to work perfectly fast and smooth.
So I suppose there are really two issues here: Why does full-screen mode cause this problem? And why is it only causing this problem on my faster computer? I do suspect there's an OS-related bug. My slow work computer is Windows XP while the home one is Windows 7. I saw in other threads that Aero on Win7 can cause Java speed issues so I tried disabling it. That did cause a small speed improvement but it still wasn't as smooth as when I ran in windowed mode. Has anyone else had performance issues running full-screen Java apps on Win7? And if so, is there a work around?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了解决方案。我偶然发现了 Oracle 的 Java 系统属性页面 (http:// docs.oracle.com/javase/1.5.0/docs/guide/2d/flags.html)并认为那里可能有一些有用的东西。在使用跟踪命令时,我注意到有很多 Direct3D 参考。由于我的应用程序中没有任何内容是 3D 的,所以我觉得这很奇怪。所以我在 Java 命令行中添加了 -Dsun.java2d.d3d=false 。正如该页面所说,该选项将“关闭 Java 2D 系统对 Direct3D 的使用”。它就像一个魅力。现在它可以在我的 Windows 7 机器上以全屏模式完美流畅地运行。
I found the solution. I stumbled upon Oracle's Java System properties page (http://docs.oracle.com/javase/1.5.0/docs/guide/2d/flags.html) and figured there might be something useful there. While using the trace command I noticed that there were a lot of Direct3D references. Since nothing in my app is 3D, I thought that strange. So I added -Dsun.java2d.d3d=false to my Java command line. As the page says that option will "turn off the Java 2D system's use of Direct3D". And it worked like a charm. Now it runs perfectly smoothly on my Windows 7 machine in full screen mode.