简体   繁体   English

为什么我的Java应用程序在全屏模式下运行得如此之慢? (当窗口时很好)

[英]Why does my Java application run so slowly in full-screen mode? (and fine when windowed)

I'm working on a Java program that is intended to run in full-screen mode. 我正在开发一个旨在以全屏模式运行的Java程序。 It uses numerous of customized Swing components and Java2D-drawn components that need to be updated and repainted several times a second. 它使用了许多定制的Swing组件和Java2D绘制的组件,需要每秒更新和重新绘制几次。 And it was working relatively fine on my underpowered work PC. 它在我的动力不足的PC上工作得相对较好。

But then I tried it out at home on my much more powerful PC. 但后来我在家里试用了功能更强大的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. 触发一个应该立即更新大约20个不同屏幕元素的事件,而不是产生一种效果,其中每个元素似乎至少需要四分之一秒来重新绘制自己。 So instead of instantaneous changes it was taking 5 seconds to complete each screen change. 因此,与完成瞬时更改相比,完成每个屏幕更改需要5秒钟。

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. 我的慢工作计算机是Windows XP,而主计算机是Windows 7.我在其他线程中看到Win7上的Aero会导致Java速度问题,所以我尝试禁用它。 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? 有没有其他人在Win7上运行全屏Java应用程序时出现性能问题? And if so, is there a work around? 如果是这样,有解决方法吗?

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. 我偶然发现了Oracle的Java System属性页面( http://docs.oracle.com/javase/1.5.0/docs/guide/2d/flags.html ),并认为可能有一些有用的东西。 While using the trace command I noticed that there were a lot of Direct3D references. 在使用trace命令时,我注意到有很多Direct3D引用。 Since nothing in my app is 3D, I thought that strange. 由于我的应用程序中没有任何东西是3D,我觉得很奇怪。 So I added -Dsun.java2d.d3d=false to my Java command line. 所以我在我的Java命令行中添加了-Dsun.java2d.d3d = false。 As the page says that option will "turn off the Java 2D system's use of Direct3D". 正如该页面所说,该选项将“关闭Java 2D系统对Direct3D的使用”。 And it worked like a charm. 它就像一个魅力。 Now it runs perfectly smoothly on my Windows 7 machine in full screen mode. 现在它在我的Windows 7机器上以全屏模式运行得非常顺畅。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM