client view of very large collection of objects. How to optimize?

270 views Asked by At

I have 3-tier EJB application, and I need to create a view on a thick client (desktop Java application) that shows a very large collection of objects (over 5000 orders). Each object has child properties that are also complex objects, for example:

class Address
{
 String value 
 // other properties
}

class Order
{
 public String Number

 // this is collection of complex object and I need first and last object to show it's
 // properties in view
 public List<Address> getAddresses()

 // other properties
}

The view is a table of Orders:

Number | FirstAddress | LastAddress | ...

My first attempt was to load full List of orders (without child properties) and then dynamically download child objects when needed for display. But when I have 10000 orders and begin fast scrolling, the UI become unresponsive.

Then I try to load all orders and all children that need to be shown in the table, but the UI gets very heavy and slow, possibly because of memory cost). And it's not thick client at all, because I download almost all data from db.

What is best practice to solve this task?

4

There are 4 answers

1
trashgod On BEST ANSWER

Assuming you are using a JTable as the view of a suitable TableModel, query the database using a SwingWorker and publish() the results as they arrive. For simplicity, this example simply fetches random data in blocks of 10. Note that the UI remains responsive as data accumulates.

0
Shivan Dragon On

It's advised to make a proxy object for your list that simply gets only a small part of it's elements, and also the total count, and then has the ability to load on demand other parts of the original list

0
home On

Follow Value Object or Data Transfer Object pattern. Send only what you really need. Instead of sending a graph of domain objects, just create one or more 'stupid' flat objects (containg simple attributes) per view.

0
karla On

I suggest implementing some sort of pagination, in other words you'll have to implement a mechanism for retrieving only a small subset of all your data, and show them chunk by chunk in different pages.

Exactly "how" depends on your approach so far.

  • you can either use some programming pattern like those already mentioned
  • or you can implement it at DB level, where you query your DB server, i.e. depending on the chosen DBMS you'll have to write the fetch
    queries in such a manner that they retrieve only a portion of all the data, like in here.

hope this helps!