Java – store data in memory
I have "table a" in the database, which contains three columns "col 1", "col 2" and "col 3", with about 1000000 (1 million) records
For this table, I have mapped a simple POJO. Let's say that "classA" has three instance variables "VAR1", "var2", "var3", and also defines set () and get () methods
My application contains simple JSP, servlet and POJO, no fancy framework and no other technology
What I really want is that when my application is deployed on the application server for the first time and it receives the first request, only that request (only once) my servlet will get 1 million records a from table, map classA with these records, start filling objects for classA, and save them in vector or ArrayList, Because you may already know that my vector / ArrayList will now contain 1 million objects, each representing a record / tupple in "tableA"
OK, now to the real and difficult part, I want to store / save / add the vector / ArrayList to the application context or VM or any other memory storage location (actually I don't know), so that every time my JSP page / servlet accesses an object in memory, I have to get data instead of accessing the database
Solution
You must use the Java cache system (see here) or ehcache (see here) to store data in the cache. The inversion of control in spring is also helpful to some extent, but it is not sure whether it helps to store 1 million data in the heap, because the heap memory is limited