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

I have a three-tier EJB application, and I need to create a view for a thick client (Java desktop application) that shows a very large collection of objects (more than 5000 orders). Each object has child properties, which 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 | Last Address | ...

My first attempt was to load a complete list of orders (without child properties) and then dynamically load child objects when needed for display. But when I have 10,000 orders and start scrolling quickly, the user interface becomes unresponsive.

Then I try to load all the orders and all the children that should appear in the table, but the user interface becomes very heavy and slow, possibly due to the cost of memory). And this is not a fat client at all, because I download almost all the data from db.

What is the best practice for solving this problem?

+4
source share
4 answers

Assuming you are using JTable as the representation of a suitable TableModel , query the database using SwingWorker and publish() results as they become available. For simplicity, this example simply retrieves random data in blocks of 10. Note that the user interface remains sensitive as data accumulates.

+2
source

Follow the Object Object or Data Transfer Object. Submit only what you really need. Instead of sending a graph of domain objects, simply create one or more “silly” flat objects (containing simple attributes) for each view.

+2
source

I propose to implement some kind of pagination, in other words, you have to implement a mechanism to extract only a small subset of all your data and show them a fragment in a piece on different pages.

The exact “how” depends on your approach so far.

  • you can use some kind of programming pattern, as already mentioned
  • or you can implement it at the database level, where you request your database server, that is, depending on the chosen DBMS, you will need to write a selection of queries in such a way that they extract only part of all the data, as in here.

hope this helps!

+2
source

It is recommended to create a proxy object for your list, which simply receives only a small part of its elements, as well as the total, and then has the ability to load other parts of the original list on demand

+1
source

All Articles