aspose file tools*
The moose likes Servlets and the fly likes Storing data in memory from Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Storing data in memory from Servlet" Watch "Storing data in memory from Servlet" New topic
Author

Storing data in memory from Servlet

Bilal Ali
Ranch Hand

Joined: Jun 14, 2007
Posts: 66
I have "TABLE A" in database which contains 3 columns "COL 1" , "COL 2" and "COL 3" with around 1000000 (1 Million) records.

Against this table I have mapped a simple POJO lets say "ClassA" with 3 instance variables "var1" , "var2" , "var3" and also defined there set() and get() methods .

My application contains simple JSPs , Servlets and POJOs with no fancy frameworks and no other technologies .

What I actually want is that when first time my application is going to be deployed on the Application Server and the very first request which it receives , only for that request (only 1 time) my Servlet is going to get the 1 Million records from TABLE A , maps the ClassA with these records and starts populating the objects for ClassA and keep them in a Vector or an ArrayList , as you might have understood that my Vector/ArrayList will now contain 1 Million objects with each object representing a record/tupple in the "TableA" .

OK , now come to the real and difficult part , I want this Vector/ArrayList to be stored/persisted/added to the application context or to the VM or to any other memory storage location (which actually I do not know) , so that each time my JSP pages/Servlets are accessing the object in memory of getting data and not hitting the database every time .

I am totally unable to understand that how to technically achieve it , please guide me because I am layman and have no clue of how to achieve this objective.
gurunath pai
Greenhorn

Joined: Dec 10, 2012
Posts: 13

you have to use Java Caching System(http://jakarta.apache.org/jcs/index.html) or http://ehcache.org/ to store data in cache, Inversion of Control in Spring also helps in some way but not sure whether it would help to store 1 million data in heap, as heap memory is limited.


“Anyone who has never made a mistake has never tried anything new.” ― Albert Einstein
Bilal Ali
Ranch Hand

Joined: Jun 14, 2007
Posts: 66
Can I use "Application Context" to store this data , I came to it while doing google , also please what is Application Contect .
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Why on earth would you want to pre-read a million rows and store them in memory? That's crazy.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
gurunath pai
Greenhorn

Joined: Dec 10, 2012
Posts: 13

Application context again uses the same heap of JVM, as we know heap memory is limited, I don't think you can store such a huge set of data in a context. It is not a good practice as well. So the last option is to use some caching mechanism at server side, so that you can avoid DB hit or just go with NoSql technology.
Bilal Ali
Ranch Hand

Joined: Jun 14, 2007
Posts: 66
can you please tell what is the size of jvm heap , I mean to sy that how many maximum records can be stored in it ?
gurunath pai
Greenhorn

Joined: Dec 10, 2012
Posts: 13

Can you just tell me, why do you want to store such a huge data in Context ? Cache works much better for these.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Storing data in memory from Servlet