将数据存储在内存中 [英] Storing data in memory

查看:87
本文介绍了将数据存储在内存中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中有"TABLE A",其中包含3列"COL 1" , "COL 2" and "COL 3",大约有1000000条记录(一百万).

I have "TABLE A" in database which contains 3 columns "COL 1" , "COL 2" and "COL 3" with around 1000000 (1 Million) records.

针对此表,我已经映射了一个简单的POJO,比如说"ClassA"带有3个实例变量"var1" , "var2" , "var3",并且还在其中定义了set()get()方法.

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 .

我的应用程序包含简单的JSP,Servlet和POJO,没有花哨的框架,也没有其他技术.

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

我真正想要的是,当我的应用程序第一次部署在Application Server上并且它收到的第一个请求时,仅针对该请求(仅1次),我的Servlet将获得100万TABLE A中的记录,将这些记录映射到ClassA并开始填充ClassA的对象,并将它们保存在Vector或ArrayList中,因为您可能已经了解到,我的Vector/ArrayList现在将包含100万个对象每个"TableA"中代表record/tupple的对象.

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" .

好,现在到了真正困难的部分,我希望此Vector/ArrayList成为应用程序上下文,VM或任何其他内存存储位置(实际上我不知道)的stored/persisted/added,所以每次我的JSP pages/Servlets每次访问内存中的对象以获取数据而不是每次都未访问数据库时.

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 .

推荐答案

您必须使用 Java缓存系统(请参见此处)以将数据存储在缓存中, Spring 中的控制反转在某种程度上也有所帮助,但不确定是否有助于将100万个数据作为堆存储在堆中内存有限.

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.

这篇关于将数据存储在内存中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆