wood burning stoves 2.0*
The moose likes Java in General and the fly likes Too many columns slowing down program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Too many columns slowing down program" Watch "Too many columns slowing down program" New topic
Author

Too many columns slowing down program

Gulshan Singh
Ranch Hand

Joined: Apr 22, 2009
Posts: 41
I have two questions. I'll start by posting my code:


First of all, in my main loop, I'm going to have to access all of my JTextFields. I wanted to put the buildGUI function seperate from the main loop which is good programming practice, but I would have to make all of the TextFields global, which is bad programming practice. Should I leave it like it is or is there a solution to this problem?

Secondly, the program runs fine the way it is now, but if I add a few more columns its starts to lag horribly... What is causing this lag and how do I fix it?
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
I don't see a break statement for the outer loop.


JDBCSupport - An easy to use, light-weight JDBC framework -
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11256
    
  16

Generally, it is impossible (or at least VERY HARD) to find where the slowdown is by looking at the code. It's almost NEVER where you think it would be. The best way to find it is to get some kind of profiler that will show you where your code is spending all it's time. Then you can focus on that part.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Gulshan Singh
Ranch Hand

Joined: Apr 22, 2009
Posts: 41
Well the fact that the outer loop doesn't break can't be the problem. Even if I have four columns, the code in the loop where the program is spending its time is the same. If I have 8 columns, the code in the loop is still the same. So it doesn't make sense that it's getting slower when its looping through the same code in both situations... any ideas?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19680
    
  18

I'd say it would definitely slow down your application. Your program will constantly be executing the loop. Although it may not execute any code, it will still check, and check, and check, and check, and check... In other words, your CPU will be very very busy.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Gulshan Singh
Ranch Hand

Joined: Apr 22, 2009
Posts: 41
But what I'm saying is, even though it checks and checks and checks, the number of checks is going to be the same no matter how many columns there are, because its only checking for one column during the loop. I'll change it so its more efficient in general, but I'm going to guess that the problem with the columns will still apply. I'll post back when I make the changes.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Gulshan Singh wrote:I'll post back when I make the changes.


I would suggest you need a selection listener on your table, so you only do that code when the selected row changes.
 
Consider Paul's rocket mass heater.
 
subject: Too many columns slowing down program