• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to improve performance of Swing application  RSS feed

 
Sanjay Chougule
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a Java audio player,developed in Swing and Sound API. Currently GUI thread are decreasing CPU performance.So please suggest me to improve performance.

Thanks in Advance.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you know that the GUI thread impacts performance? What is the GUI doing that would take a noticeable amount of time?
 
Sanjay Chougule
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Jprofile which gives me following CPU usage report


85.6% - 2,058 ms - 1 inv. com..avp.XYZVoicePlayerFrame
5.8% - 138 ms - 6 inv. direct calls to methods of filtered classes
4.5% - 107 ms - 1 inv. java.awt.EventDispatchThread
4.0% - 96,049 �s - 1 inv. com.XYZ.avp.audio.PlayThread
0.2% - 3,763 �s - 1 inv. com..avp.audio.AudioRecorder

most CPUY consuming class is avp.XYZVoicePlayerFrame which is GUI class.

I think it is sufficient to understand issue..
thanks
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I doubt that it's Swing itself using up all that time - it's not a Swing class, it's one of your application's classes. Check the code if there's some busy waiting going on, or it includes time spent by the media player.

Also, 2 seconds isn't much to go by - I'd profile it for a longer time.
 
Sanjay Chougule
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, you are right.
Here are few threads going in wait state for long time.
Report showing that only running threads very few and waiting thread are 6 to 7 .
Then how to resolve this.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The important thing is not so much the number of threads, it's what the threads are doing. A sleeping thread doesn't use up CPU time. If a thread executes a loop over and over w/o doing anything, that's a problem. Any loop similar to this:

should be changed to something like this, using a sleep value that's appropriate for the application:

[ July 04, 2008: Message edited by: Ulf Dittmer ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JProfiler should also give you a report on which method in that class consumes the cpu that much.
 
Sanjay Chougule
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for guiding.....

Currently following method is taking 19.6 % CPU useage: Please find out mistakes so that performance will improve.

As I am very fresher and also currently i am exploring Swing, your help is very valuable for me.

/**
* Sets the lF.
*
* @param LFclassname the new lF
*/
void setLF(String LFclassname) {
try {
UIManager.setLookAndFeel(LFclassname);
SwingUtilities.updateComponentTreeUI(this.avpFrame);
LookAndFeel lfcur = UIManager.getLookAndFeel();

for (int ii = 0; ii < this.lf.length; ii++) {
if (lfcur.getName() == this.lf[ii].getName()) {
this.LookAndFeelInuseIndex = ii;
this.LookAndFeelinuse = LFclassname;
}
}
} catch (ClassNotFoundException e1) {
} catch (InstantiationException e2) {
} catch (IllegalAccessException e3) {
} catch (UnsupportedLookAndFeelException e4) {
}
}

here is CPU useage Report:
Thread selection: All thread groups
Thread status: Runnable
Aggregation level: Methods

78.0% - 1,957 ms - 1 inv. com.xyz.avp.xyz.VoicePlayerFrame.main
71.0% - 1,783 ms - 1 inv. com.xyz..avp.xyz.VoicePlayerFrame.<init>
21.7% - 545 ms - 1 inv. com.xyz..avp.xyz.VoicePlayerFrame.loadPersist
20.8% - 522 ms - 1 inv. com.xyz..avp.xyz.VoicePlayerFrame.setLF
19.6% - 491 ms - 1 inv. javax.swing.SwingUtilities.updateComponentTreeUI

13.7% - 343 ms - 1 inv. com.xyz..avp.AvpMediator.setFileChoose
13.2% - 331 ms - 1 inv. javax.swing.JFrame.<init>



Thanks once again.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code you posted does nothing that would take any appreciable amount of time, so we can't guess what might be going on.

But this looks wrong (not that it has anything to do with performance). You should never compare strings using "==" - that's what the equals method is for:


This is bad, too. You should at least print an error message to System.err so that you know something went wrong:
 
Sanjay Chougule
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How long did the application run already, when you created the cpu usage report?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!