为什么我的Java应用程序在全屏模式下运行得如此之慢? (当窗口时很好) [英] Why does my Java application run so slowly in full-screen mode? (and fine when windowed)

查看:248
本文介绍了为什么我的Java应用程序在全屏模式下运行得如此之慢? (当窗口时很好)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个旨在以全屏模式运行的Java程序。它使用了许多定制的Swing组件和Java2D绘制的组件,需要每秒更新和重新绘制几次。它在我的动力不足的PC上工作得相对较好。

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.

然后我在家里试用了功能更强大的PC。它的运行速度明显变慢了。触发一个应该立即更新大约20个不同屏幕元素的事件反而导致一个效果,每个元素似乎至少需要四分之一秒来重新绘制自己。因此,不是瞬间更改,而是需要5秒钟才能完成每次更换屏幕。

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.

所以我认为这里确实存在两个问题:为什么全屏模式会导致这个问题?为什么它只会在我更快的计算机上造成这个问题?我确实怀疑存在与操作系统相关的错误。我的慢工作计算机是Windows XP,而主计算机是Windows 7.我在其他线程中看到Win7上的Aero会导致Java速度问题,所以我尝试禁用它。这确实导致了一个小的速度改进,但它仍然不像我在窗口模式下运行时那么顺畅。有没有其他人在Win7上运行全屏Java应用程序时出现性能问题?如果有,是否有解决方法?

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?

推荐答案

我找到了解决方案。我偶然发现了Oracle的Java System属性页面( http:// docs.oracle.com/javase/1.5.0/docs/guide/2d/flags.html )并认为那里可能有一些有用的东西。在使用trace命令时,我注意到有很多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.

这篇关于为什么我的Java应用程序在全屏模式下运行得如此之慢? (当窗口时很好)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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