views:

108

answers:

1

Hi all, I have written my jsp using <display:table> to display search results. The <display:table> requires a javabean list to be passed in as an argument. Currently a controller will build the list, then the jsp displays it.

My concern is that what happen if 1000 users perform search at a time. That means all results will need to be loaded to memory as different javabean lists for <display:table> to display. The system will possibly crash because of running out of memory. Is there good strategies to prevent the system running out of memory? Is there a way in application level to limit the number of users to load the application? Would it mean using <display:table> is a bad programming practice since all records have to be loaded into memory at once? Thanks in advance.

+1  A: 

This is a very valid concern. You shouldn't unnecessarily allocate memory. Displaytag unfortunately doesn't support pagination at database level. Everything has to be loaded into Java's memory first. The most memory efficient approach is obviously to store only the data in memory which the enduser is going to see and fire a new HTTP request to the server to retrieve exactly those new rows from the DB on every button click.

No other JSP based pagination tag which does that comes to mind. If you were using JSF, I would have recommended PrimeFaces' <p:dataTable dynamic="true"> for this. You still have to write code which is retrieving exactly the particular rows from the DB. But this isn't that hard when you're using Hibernate and/or JPA.

In "plain vanilla" JSP/JSTL you have to do a bit more work. Basically, you need to provide a bunch of buttons which will modify the value of firstrow and invoke action to retrieve the data from DB accordingly. I've answered this in detail before in this topic: ResultSet to Pagination.

BalusC
COOL!!! Your detail example in the other post is so helpful. The JSF technology combining with AJAX sounds very interesting and useful. I should read some more when I have time. Thank you heaps, Balus!!
Kenneth
You're welcome. JSF is definitely cool (particularly the current version 2.0). But I would recommend to not learn it yet until you have a good grasp on JSP/Servlet. Else it's very hard to understand what JSF is doing "under the hoods" (since it runs on top of Servlet API). First learn "plain" JSP/Servlet and "plain/homegrown" MVC and then you'll better understand why JSF is there and what it is doing.
BalusC
Ok. I will do so. Thanks again.
Kenneth
You're welcome.
BalusC