• Post Reply Bookmark Topic Watch Topic
  • New Topic

Unknown thread goes wild  RSS feed

 
Ranch Hand
Posts: 116
1
Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Long story:

First, I'm an old, obsolescent programmer who can get a Java program running (in fact, I've done three fairly large programs), but I've never considered myself a pro. I'm certainly lost by many of these new-fangled concepts, like factories.

I'm running on a Mac, OS 10.6.8 (I'm leery of new versions until they've had a chance to stabilize), using Eclipse for my dev environment. No I don't understand even half of the features of Eclipse.

I recently noticed that my program was gobbling up a lot of cycles. Activity Monitor shows it eating up 100% of the cycles in one of my four processors, even when quiescent. I ran another, much larger program, also in Java, and it doesn't need any cycles at all when it's quiescent.

My first thought was that I was in some sort of auto-triggering loop: some drawing action in Swing triggers an update that executes the drawing action, triggering another update, ad infinitum. So I inserted a System.out.println("a") call into each method that alters the display, figuring that the guilty party would splatter a long sequence of "a" lines onto my console. That didn't happen. So I repeated the process with every Listener in the program. Again, no long sequence of printlns.

OK, so let's look at the thread list displayed in Eclipse debugger mode. It shows four threads running inside my app's thread: AWT Shutdown, AWT AppKit, AWT EventQueue0, and my main() method. I run the "good" app and it shows two additional threads: DestroyJavaVM and Java Sound Event Dispatcher. Since the "bad" (i.e., cycle-gobbling) app doesn't have any threads that the good app doesn't have, I conclude that I can't find the problem this way.

I was getting desperate, so I checked for obvious things: yes, there's plenty of free RAM; no, there's no disk activity or network activity taking place while the bad app is quiescent.

So I came here and searched for things like "slow" and "execution time". There were plenty of discussions of general speed issues, but nothing that I found seemed to help with my particular problem. I searched around at the Eclipse website for a tool that would help. I *know* that such a tool exists for Eclipse, but now I can't find it. The problem here is that I'm so obsolescent that I don't even know the right search terms to use. I searched on "profiler", but only found information on how to write a profiler plug-in for Eclipse.

So, if somebody would just mention a few search terms, perhaps, that would get me pointed in the right direction, that would probably be adequate. If you can point me to something that explains how to find out where the program is spending all its time, that would be even better. And the very best thing would be if somebody wrote something like "Did you remember to call the System.XXXX.YYYY() that clears out useless threads?", I'd be ecstatic.

Thanks for any help.
 
Chris Crawford
Ranch Hand
Posts: 116
1
Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found the problem, and as usual, it goes in the file folder labeled "Idiot Programmer Mistakes". This program was adapted from an older version in C++. Obviously, I had to completely rewrite most of it, and very little of the old C++ stuff is even recognizable. But I had copied and pasted some initialization code from the old program into the Java version, largely because it was just variable initializations. Down at the bottom of that code were two lines taken pretty much directly from the old C++ code:



Sure, it makes sense in an old C++ program, but it's idiocy in Java.

I hope that reading this has been (at least) entertaining.
 
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At least you found the issue. Bet this is an error you won't make again!
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!