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?