• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Anybody handles record paging to prevent OutOfMemoryError?

 
Clivant Yeo
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers,

I am in doubt of whether to implement record paging for the client application, as the client application will crash with OutOfMemoryError when a lot of records are stored in the underlying TableModel in the JTable. Welcome all opinions on this issue.

Rgds,
Clivant
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Clivant,

Have you considered how big the standard record is, and therefore how many records you will need to have in memory before you experience problems?

This is something you should think about - but as I mentioned above, I doubt that it is a major issue for this case. So you could get away with just documenting your reasoning for not catering for this issue.

But if you wanted to, you could also try lazy loading the data into a collection using SoftReferences. Then the JVM is free to discard some of your records from memory if resources run low. As long as you use lazy loading (load the record if it is not currently in the cache) then you should be fine with this.

Regards, Andrew
 
Clivant Yeo
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andrew,

At the client side, you need to have some kind of persistence for the Record number. If user selects a particuliar record after it had been garbage-collected, it will throw a NullPointerException, which is not very desirable. Furthermore, the GUI needs to comsume memory as well, if the records stored in the underlying TableModel is too huge, it will crash the program as well.
 
Fisher Daniel
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Clivant and Andrew,
I am interesting about this case.
I think it is suitable to use lazy loading when loading a huge data from database.
But I am confuse how we can synchronized a record with current value in database.

Example, we load record #A, #B and #C from database onto client computer. At the other client computers, an user updates record #B.
How does the server application notify all clients that there is value changes on record #B?

Correct me if I am wrong...

thanks
daniel
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Clivant,

Sorry, temporary brain fried - even though you were explicit in saying that you were looking at the client running out of memory, I still read it as a server side problem .

For the client side, since the find() method returns an array of record numbers, it is relatively easy to limit how many real records you retrieve and/or display at any given time. So you could limit yourself to only loading and displaying 50 records from the server at any given time and having a "next 50" and "previous 50" buttons.

To make that a bit more user friendly you could also have a separate thread which loads the "next 50" in the background while the user is viewing / working with the current 50.

But again, I think this is a little out of scope for this assignment.

Regards, Andrew
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Daniel,

You do not need to worry about updating all clients whenever one of them books a record. Think about a real reservations system (airlines being the clasic example) - as a client you do not get updates of seats being booked: it would be too much work for any given airline to update the millions of travel agents around the world.

If you really wanted to do it, you could use the Observer pattern, combined with the exportObject() call of UnicastRemoteObject to make the client act as a receiver of calls from the server as records are updated.

Since I dont think your issue has anything to do with the lazy loading scenario, nor with Clivant's question, I think if you want to discuss this further, you should open a separate topic for it.

Regards, Andrew
 
Clivant Yeo
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Andrew, I think I will do just that, but without the user friendly thread, that wouldn't be too much of a difficulty, I guess.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to put my two cents into this discussion. In a real system, I'd say there might be a good reason to take the time and consider a good solution for this potential problem. But then again in the real world, I would have a datbase that handles this issue for me, without me having to lift a nail and worry about it.

For the assignment, this is overkill and not needed to consider. The database is really small, and Sun, does not want this project to be a big deal. It is a straight forward assignment, to test your knowledge in Swing, RMI or Sockets, and basic OO design principles. In order to test this knowledge they needed to create an assignment that does not go overboard in determining a candidates skills. If anything, adding extra complicated code just makes the grader more frustrated because they have to take the extra time to decipher your "record paging" code. Because if it doesn't work, then they have to knock points off your grade. If it does work, you gain nothing extra, no bonus points, as that is not on their grading sheets.

Hope that helps. Keep it simple.

Mark
 
Clivant Yeo
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,

What you says makes sense. I reread my specifications and found out that the functionality needed are searching for records and booking a record, there is no need for the creation of records. If creation of records is not possible, how can my database file hits 70000 records? Furthermore, the specs states that this system that I am building is an interim step and much reuse is not being anticipated. I guess I would have to emphasize on these points and make an assumption that the records won't grow. In this way, I will not be wasting my time to reimplement my project, I can focus more on my final year project that is coming. Thanks for your valuable enlightenment, what's left for this daunting assignment is to check my stuffs and upload it and then take the essay exam.

Regards
Clivant
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic