Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing data in memory

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 .

like image 618
Mike Mugese Avatar asked Oct 21 '22 19:10

Mike Mugese


2 Answers

You have to use Java Caching System(see here) or Ehcache (see here) 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.

like image 82
Nicholas Bayborodin Avatar answered Oct 24 '22 16:10

Nicholas Bayborodin


It looks like you need caching, if I get you right. I would recommend to take a look on EHcache or Infinispan here.

Hope this helps

like image 43
Mark Bramnik Avatar answered Oct 24 '22 18:10

Mark Bramnik