This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
I have a Swing application where I display information using JTree. I am using TreeCellRenderer as I have icons etc. on the JTree.
I noticed that when I launch my JTree, the CPU cycles goes to 25-26 and stays there. Even though I (user) do not perform any activity on the UI, the CPU cycles still remains the same till I close the application.
I added few println statement and noticed that TreeCellRenderer's getTreeCellRenderer() method is called infinitely till the Jtree is displayed. Probably it could be the reason for high CPU cycle.
Do you any suggestions, how can I resolve the issue. How can I use TreeCellRenderer and have control the CPU cycles ?
I would start by looking at the code in your TreeCellRenderer. Remember that its method... the one with the long name and parameter list which I don't have in my memory right now... will be called frequently. So if you're doing anything non-trivial in that method, that could be a problem.
A Thakur wrote:I noticed that when I launch my JTree, the CPU cycles goes to 25-26 and stays there. Even though I (user) do not perform any activity on the UI, the CPU cycles still remains the same till I close the application.
You have a 4-core CPU, and the JVM is using one of these cores completely. On a single core CPU you would have seen a CPU usage of 99% and you would have had trouble closing the application.
Something in your renderer causes an infinite loop. Not in the traditional for/while loop sense, but it has some code that causes the tree to be repainted which causes the renderer to be called again, which causes the tree to be repainted, etc.