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
Marshal
Joined: Mar 22, 2005
Posts: 35252
7
posted
0
How do you know that the GUI thread impacts performance? What is the GUI doing that would take a noticeable amount of time?
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
Marshal
Joined: Mar 22, 2005
Posts: 35252
7
posted
0
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
Joined: Mar 04, 2008
Posts: 30
posted
0
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
Marshal
Joined: Mar 22, 2005
Posts: 35252
7
posted
0
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
Joined: Jul 11, 2001
Posts: 14112
posted
0
JProfiler should also give you a report on which method in that class consumes the cpu that much.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Sanjay Chougule
Ranch Hand
Joined: Mar 04, 2008
Posts: 30
posted
0
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();
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
Marshal
Joined: Mar 22, 2005
Posts: 35252
7
posted
0
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
Joined: Mar 04, 2008
Posts: 30
posted
0
Thanks.
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
posted
0
How long did the application run already, when you created the cpu usage report?