JApplet 的运行速度比 Java 应用程序 GUI 慢 30 倍 [英] JApplet runs 30x slower than Java application GUI

查看:66
本文介绍了JApplet 的运行速度比 Java 应用程序 GUI 慢 30 倍的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 HPC 工作.我有一个小程序和一个 Java 客户端应用程序,它们通过从我们的 TORQUE 作业调度程序接收到的信息显示有关在集群上运行的作业(jobID、jobname、userID 等)的信息.

最近,我添加了按钮以按升序或降序值按类别对数据进行排序.有了这个附加功能,用户可以通过对数据进行排序来强制更新显示(以前我有一个计时器,每 10 秒从服务器接收一次新数据,然后更新显示),我注意到性能上的差异- 小程序明显滞后.放入计时代码,我发现应用程序平均需要 0.05 秒来 setContentPane() 而小程序平均需要 1.50 秒才能使用相同的代码执行相同的操作.无论小程序是在小程序查看器还是浏览器中运行,这个问题都是一样的.

我想强调的是,几乎所有的代码都是一样的.唯一显着的区别是 JApplet 对自身进行 setContentPane()(和其他)调用,而我的应用程序对 JFrame 进行这些调用(例如 frame.setContentPane()).

奇怪的是,小程序第一次调用 setContentPane() 会在大约 0.13 秒后返回.但是,所有后续调用都需要前面注明的时间.

有什么建议吗?我更希望有一个功能正常的小程序,这样我就不必将应用程序推送到我的用户社区.

JApplet 的事件处理不是问题:JApplet 和 Java 应用程序在鼠标移动和位置读取以及玻璃窗格上的弹出式绘图方面的性能是相同的.

Edit2:我刚刚编辑了 JApplet 代码,所以一个 JFrame 弹出,应用程序在其中运行,并且性能与应用程序相匹配!Applets 是什么?我已经阅读了几个星期,但没有人阐明这个问题——几乎完全是小程序不能在我的 linux 机器上的 firefox 浏览器中运行"或我如何将我的应用程序变成小程序".没有人能告诉我为什么实际上相同的相同 GUI 代码在 JApplet 中运行速度会慢得离谱.也就是说,为什么 setContentPane() 在从 JFrame 创建的 JApplet 中慢了 30 倍???

我运行小程序的原因是因为我希望它嵌入到网页中,弹出的 JFrame 太具有侵入性.想法?

Edit3:在继续我对这个问题的诊断过程中,我发现 JApplet 对 setContentPane() 的调用使我的 CPU 使用率飙升至 60-100%.应用程序的 setContentPane() 不是这种情况,它只会从 0.1% 跳到 ~4%.是什么导致了 JApplet 的所有操作和性能开销?

解决方案

奇怪的是,小程序第一次调用 setContentPane() 会在大约 0.13 秒后返回.但是,..有什么建议吗?

在第一次调用中,添加一个带有 CardLayout 的面板.永远不要再次调用 setContentPane(),而是使用带有卡片布局的面板来添加"更多内容.

I work in HPC. I have both an applet and a Java client application that display information about jobs (jobID, jobname, userID, etc.) running on the cluster via information received from our TORQUE job scheduler.

Recently, I added buttons to sort the data by category by ascending or descending values. With this addition, where the user has the ability to force an update of the display by sorting the data (previously I had a timer that received new data from the server every 10 seconds and subsequently updated the display), I noticed a disparity in performance - the applet lagged significantly. Putting in timing code, I found that the application took an average of 0.05 seconds to setContentPane() whereas the applet took an average of 1.50 seconds to perform the same operation with the same code. This issue is the same whether the applet is being run in appletviewer or a browser.

I want to emphasize that virtually all of the code is the same. The only significant difference is that the JApplet makes setContentPane() (and other) calls on itself, whereas my application makes these calls on the JFrame (e.g. frame.setContentPane() ).

Curiously, the first call to setContentPane() for the applet returns in ~0.13 seconds. However, all subsequent calls require the previously noted time.

Any suggestions? I'd much rather have a functioning applet so I don't have to push the application on my user community.

Edit: JApplet's event handling is not the issue: performance regarding mouse movement and position reading as well as popup drawing on the glass pane is identical between the JApplet and the Java application.

Edit2: I just edited the JApplet code so a JFrame pops up with the application running inside and the performance matches that of the application! What is it with Applets? I've been reading about them for weeks and no one has shed light on this problem - It's almost exclusively "applets don't run in my firefox browser on my linux box" or "how do I turn my application into an applet." No one can tell me why the same GUI code that is literally identical will run ridiculously slow inside a JApplet. That is, why does setContentPane() have a 30x slowdown in a JApplet created from a JFrame???

The reason I'm running an applet is because i want it embedded in a web page, the pop-up JFrame is too intrusive. Thoughts?

Edit3: In continuing my diagnostics of this problem, I found that a call to setContentPane() by the JApplet spikes my CPU usage up to anywhere from 60-100%. This is not the case for the application's setContentPane() which will only jump from 0.1% to ~4%. What is causing all of the operational and performance-taxing overhead for the JApplet?

解决方案

Curiously, the first call to setContentPane() for the applet returns in ~0.13 seconds. However, .. Any suggestions?

In that first call, add a panel with a CardLayout. Never call setContentPane() again, but instead use the panel with card layout to 'add' anything more.

这篇关于JApplet 的运行速度比 Java 应用程序 GUI 慢 30 倍的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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