File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Persisting objects (in memory) in application scope Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Persisting objects (in memory) in application scope" Watch "Persisting objects (in memory) in application scope" New topic

Persisting objects (in memory) in application scope

Kevin Fedric

Joined: Jan 29, 2012
Posts: 4
First let me brief you with app structure. Client is ExtJS UI and any request to data from server involves call to specific JSP page at server. JSP page in-turn invokes method from core java classes in 'data' package to get the requested data. This data returned by method call is in json format, so JSP simply returns the data back to client. I am using MySQL database and the JDBC stuff is handled by core java classes in 'data' package.

Now, the client has to get data from back end by making two subsequent separate calls to back end. These call happen on user interaction. In first call, say Call-1 queries one set of data from mysql (for example - a list of employees) and returns to client. On second, subsequent call (Call-2) the backend has to work with data already retrieved in Call-1. (For example, return Facebook profile URLs of each employee in the list retrieved in call-1).
Now I want a way to keep the list of employees (of call-1) in memory, so that I can directly start processing data from call-2 instead of querying mysql again.

I searched in google to do this, and I came across the concepts of session variables, application variables, context variables, etc. Being a newbie, am not sure which is the correct choice. I need to dig deeper in that, but given the limited time I have to work on this - I just thought of asking here for the right direction. I will appreciate some help on this front from forum members.

I have recently got into server side programming with Java. So it would be great to have some feedback on my application structure. Am I following the usual common/standard way to structure the client/server/db interactions (use of core java classes interacting directly with JSPs) and stuff like that? How and what can I improve in structuring the application.

Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 32819

Search for MVC (model view controller). It shows how to have your Java objects interact with the JSP. The short story is that the JSPs just render the view and don't have any logic. This happens from a servlet before the JSP gets called.

It is common to store data in the HttpSession. Especially if it is user specific or short lived (session scored). Unless it is huge. All of these conditions sound like they match your scenario. The application context is for global cached type data.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63548

Please read this article.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Persisting objects (in memory) in application scope
It's not a secret anymore!