Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Pagination & Session Management

 
Mohit Sinha
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Currently we are working on displaying user specific search results.
Ideally for any pagination strategies we can choose from either a cache based (store resultsets in session) or query based (database call for each subset of rows to display). Each has it own merit.

In our situation we have to display 20 records each time to the user.
In our case to fetch the data subsets we have to make a web service call & not a database call. This web service also accepts a parameter of the number of records to fetch.
Since making a web service call everytime the user clicks next & fetch the 20 records to be shown on the screen will have a high latency & we also cannot opt for fetching all the records & storing it in session as we would be having a very high number of users accessing the system & storing all the resultsets in the session may not scale well.

With this regard we are thinking of adopting a hybrid approach where in we get 100 records, store it in the session & serve the user out of those first lot of 100 records from the session. Say when the user requests for data from 101-120 we make anther web service call , fetch the next set of 100 records & slam it into the same session variable replacing the first lot of 100.
Now say the user accesses the 91-100 we make a web service call again to fetch the first set of 100 records. So the web service calls to fetch the records will only happen at intervals of 91-100,101-110 & for all other requests like 71-80 or say 121-130 likes the data will be served from the session.


Do post your suggestions on the same.


Regards
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had done something similar before. I would also suggest looking at some of the java caching solutions. Some are open source.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like a reasonable strategy. When it comes time to retrieve the next block of 100 records, you may want to do that in a separate thread, so that the request for rows 91-100 doesn't have to wait until rows 101-200 have been retrieved.

It may also be advantageous to use a single shared cache rather than saving the record in the session. Particularly if your application is one in which multiple users are likely to be viewing the same records. Also it may be easier to manage the cache if it's in one place, so you can expire older entries, or reduce or expand the size of the cache based on available memory or performance tuning parameters. And yes, check out the available java caching solutions to save yourself some time.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you cache primary keys instead of complete records? Then you could retrieve individual records by key or use a range of keys to hit the db again. Might be worth the extra effort ... or not.
 
raj vin
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If user needs 91 to 110 records, Is it 2 web service calls ?
 
Mohit Sinha
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Raj,

Your are right. The second set of records from 101-200 is a separate webservice call.
Also the search results retrieved would be user specific & not shared amongst other users.

Regards,
 
ashish jadhav
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi mohit,
i am also working on same stub of web service in java.i created one web service which insert data in DB.but i want to set time interval to insert data in DB in specific time interval.can you please help me? how set time interval in java web service??
 
ashish jadhav
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I mean to say,stored records in cache and write to DB after specific time interval
eg. time interval= 2sec.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic