Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

CPU usage is 53% for my stand alone application.  RSS feed

 
VenuArchana Aradhyula
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have developed a standalone application using Swings. I have overridden the JPanel's paintComponent() for my background images. And for the entire application i have used GridBagLayout. Now when i run the application it is using 53% of my CPU without any operation on the application.
Is paint running in thread if override the paintComponent(). Suggest me.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
53% is too much.

Is this the first time you are tweaking the paint?
If yes, it might be worth your while to check this out.
http://faq.javaranch.com/java/BackgroundImageOnJPanel

If you feel you know exactly what your code is doing, can you post your paint code so we can take a look?

PS. I am hoping you have definitely identified that the paint is the culprit and its not some other code.
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show us your painting code? I've also had this problem once, where my painting code actually caused a repaint again (because of a font change), which again lead to a repaint, etc.
I think your problem may have a similar cause - the paint triggering a repaint.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question has been cross-posted by the OP in multiple Java fora.
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that case, VenuArchana, could you please read Be Forthright When Cross Posting To Other Sites?
 
VenuArchana Aradhyula
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the code used in the paintComponent() of JPanel which creates my background image.


Is this paint method creating any problem or is there any other cause to this.

Thanks
Archana
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by VenuArchana Aradhyula:

[/QB]


You don't really need these two here.
Comment them out and let us know if there is any difference.

What replies did you get from the other places where you cross posted?

 
VenuArchana Aradhyula
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have commented the code and executed the application it is using only 12% of the CPU.
Thanks for your help
You have really solved my problem very easily.
Archana
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome

I hope you really have taken out time to read the link which Rob had provided.
http://faq.javaranch.com/java/BeForthrightWhenCrossPostingToOtherSites
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem was that repaint will, in the end, call paintComponent again. You either have hyperthreading on, or have a multi-core processor, because otherwise the load would have gone up to 99%.

One more improvement: include a call to super.paintComponent on the first line:


And I could see some humour in this:

Downgrading to Graphics1D are we? (check the variable name)


Final question: what exceptions do you expect to catch? I rarely see exceptions being caught in paint methods.
[ October 03, 2008: Message edited by: Rob Prime ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!