CPU usage Swing vs AWT

568 views
Skip to first unread message

BrittaF

unread,
Jan 31, 2013, 2:38:00 PM1/31/13
to jz...@googlegroups.com
 
We have an application running jzy3d 0.9 jar where we have jzy3d graphs embedded in our application and then we also have a popup option that displays just the graph in a window that allows you to stretch it larger to see it better. The application is swing but the popup is a JFrame that uses the "awt" chart because of the issues with trying to stretch a "swing" chart. This all works fine, but we noticed that when the popup is running there is constantly CPU usage from our application. If we don't use the popup then there isn't. And in our threads there is one thread called AWTAnimator that looks like it's constantly redisplaying or something. Also when we close the popup this thread keeps running and CPU usage keeps going. Again if we don't use the popup (with awt chart) we don't see this thread or extra CPU usage.
 
So I was wondering if there's anything we should do when closing the popup to make sure the animator stops? Also is there any reason why there's this animiator in awt but not swing, and some suggestion for a way to have a popup I can stretch without ending up with this extra CPU usage (some way to turn off animator, better way to construct popup, etc)?
 
Here's how i create the popup:
 

JFrame newFrame =

new JFrame();

newFrame.setContentPane(graphView);

 
where graphView is an object that contains a chart, and to initialize that chart we do:
 

currentChart

= new Chart(Quality.Advanced, "awt");

And to add it to the JPanel:

 

jzy3DPanel

.add((Component) currentChart.getCanvas(), BorderLayout.CENTER);

 

Martin Pernollet

unread,
Feb 5, 2013, 5:34:33 PM2/5/13
to Jzy3d
Hi,

To completely kill the chart, call chart.dispose(). It will stop the animator, and call all possible dispose() methods of your drawables (in case some of them use native resources, etc).

The swing canvas has been updated some time ago, but keep in mind this canvas might not be supported in the future as jogl guys tend to focus on a new canvas type called Newt. Some jzy3d users reported good performance of the "newt" chart in swing layouts, and I personnaly found it great on awt. For the moment that canvas is only available on the github repo, but will appear in next release.

Martin



2013/1/31 BrittaF <britta....@gmail.com>

--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes Jzy3d.
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse jzy3d+un...@googlegroups.com.
Pour plus d'options, visitez le site https://groups.google.com/groups/opt_out .
 
 

BrittaF

unread,
Feb 13, 2013, 11:21:37 AM2/13/13
to jz...@googlegroups.com
So I added a window listener and on windowClosing() i'm calling dispose on all my shapes followed by dispose on my chart. It does seem to stop the animator, everything seems to work fine, but I am getting a couple of exceptions. They don't seem to cause me problems but i'm wondering if i'm doing something wrong, missing something or in the wrong order.
 
 

Exception in thread "AWT-EventQueue-0-AWTAnimator-2"

java.lang.RuntimeException: java.lang.NullPointerException


        at jogamp.common.awt.AWTEDTExecutor.invoke(

AWTEDTExecutor.java:58)


        at jogamp.opengl.awt.AWTThreadingPlugin.invokeOnOpenGLThread(

AWTThreadingPlugin.java:103)


        at jogamp.opengl.ThreadingImpl.invokeOnOpenGLThread(

ThreadingImpl.java:205)


        at javax.media.opengl.Threading.invokeOnOpenGLThread(

Threading.java:172)


        at javax.media.opengl.Threading.invoke(

Threading.java:191)


        at javax.media.opengl.awt.GLCanvas.display(

GLCanvas.java:449)


        at com.jogamp.opengl.util.AWTAnimatorImpl.display(

AWTAnimatorImpl.java:74)


        at com.jogamp.opengl.util.AnimatorBase.display(

AnimatorBase.java:142)


        at com.jogamp.opengl.util.Animator$MainLoop.run(

Animator.java:176)


        at java.lang.Thread.run(Unknown Source)


Caused by:

java.lang.NullPointerException


        at org.jzy3d.chart.ChartView.render(

ChartView.java:65)


        at org.jzy3d.plot3d.rendering.view.Renderer3d.display(

Renderer3d.java:76)


        at jogamp.opengl.GLDrawableHelper.displayImpl(

GLDrawableHelper.java:373)


        at jogamp.opengl.GLDrawableHelper.display(

GLDrawableHelper.java:358)


        at javax.media.opengl.awt.GLCanvas$7.run(

GLCanvas.java:983)


        at jogamp.opengl.GLDrawableHelper.invokeGLImpl(

GLDrawableHelper.java:655)


        at jogamp.opengl.GLDrawableHelper.invokeGL(

GLDrawableHelper.java:594)


        at javax.media.opengl.awt.GLCanvas$8.run(

GLCanvas.java:996)


        at java.awt.event.InvocationEvent.dispatch(Unknown Source)


        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)


        at java.awt.EventQueue.access$000(Unknown Source)


        at java.awt.EventQueue$1.run(Unknown Source)


        at java.awt.EventQueue$1.run(Unknown Source)


        at java.security.AccessController.doPrivileged(

Native Method)


        at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)


        at java.awt.EventQueue.dispatchEvent(Unknown Source)


        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)


        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)


        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)


        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)


        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)


        at java.awt.EventDispatchThread.run(Unknown Source)


BrittaF

unread,
Feb 13, 2013, 2:59:39 PM2/13/13
to jz...@googlegroups.com
 
Ok so I was able to get the animator to stop by calling canvas.dispose without getting exceptions. there might have been some timing condition.
 
But I have another question related to the animator, it seems that my memory also keeps growing and growing while the animator is running. Have you seen this before? 

Martin Pernollet

unread,
Feb 13, 2013, 3:05:26 PM2/13/13
to Jzy3d



2013/2/13 BrittaF <britta....@gmail.com>

 
Ok so I was able to get the animator to stop by calling canvas.dispose without getting exceptions. there might have been some timing condition.

After looking closer, dispose() might trigger the NPE you mentionned if you call dispose during a rendering cycle... Added the issue https://github.com/jzy3d/jzy3d-api/issues/6
You might also simply call canvas.getAnimator().stop()

 
 But I have another question related to the animator, it seems that my memory also keeps growing and growing while the animator is running. Have you seen this before? 

No, but you can discuss that point on jogl forum, as animator is part of the jogl framework.

BrittaF

unread,
Feb 13, 2013, 5:25:53 PM2/13/13
to jz...@googlegroups.com
Actually i was wondering what the purpose of the animator is in this case? I tried modifying the code to not start the animator at all and it seems to work ok.. This is with the previous 0.9 jar version, not the most recent by the way. I did have to call repaint after adding a popup though, which i have to do with swing also. That seems like the biggest difference so far.

Martin Pernollet

unread,
Feb 13, 2013, 6:26:18 PM2/13/13
to Jzy3d
At the beginning, jzy3d was using a "repaint on demand" model, where each controller/modifier queries a rendering update, with no rendering when nothing changes.
When starting to port from jogl to jogl2, I had a problem to receive events from GLEventListener when the window was resized, and jogl developpers suggested to switch to a "continuous rendering" model, using the Animator class. 
If you prefer no animator, you should verify that resizing the chart works properly, maybe the problem is fixed @ version rc10 or latter.
Another possibility is to usea FPSAnimator:





2013/2/13 BrittaF <britta....@gmail.com>

BrittaF

unread,
Feb 14, 2013, 3:52:34 PM2/14/13
to jz...@googlegroups.com
So FYI I have the latest jogl jars, so it could be some improvements were made. I'll have to keep an eye on this going forward too.
 
So in case others are interested, where I'm using the CanvasAWT is in a popup JFrame. What was happening though is that while my main window's graph was updating rapidly (while a process is running and adding points, etc), then the popup would appear blank. But, if the main window graph wasn't updating rapidly then my popup graph would appear just fine. (My main window is using CanvasSwing). Anyway, what I ended up doing was adding a ComponentListener for when the component resized to call display(). It does work but is still a bit slower than animator while my other graph is updating. I also had to call display() after i called pack() on my popup frame. And I also am calling it when I add or remove tool tips to the popup graph, since these also wouldn't work while the other graph is running. Anyway now everything at least outwardly appears to be working fine now and no one can complain about the extra potential CPU or memory, I think, in case it's a concern.

Thanks
Reply all
Reply to author
Forward
0 new messages