java 在内存中存储数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14313862/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 15:50:48  来源:igfitidea点击:

Storing data in memory

javajspservletspojo

提问by Mike Mugese

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

"TABLE A"在数据库中包含 3 列"COL 1" , "COL 2" and "COL 3",其中包含大约1000000(100 万)条记录。

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

对这个表我制订一个简单的POJO比方说"ClassA"用3个实例变量"var1" , "var2" , "var3",并在那里定义set()get()方法。

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

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

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 ClassAand keep them in a Vector or an ArrayList, as you might have understood that my Vector/ArrayListwill now contain 1 Million objects with each object representing a record/tupplein the "TableA".

我真正想要的是,当我的应用程序第一次部署在应用程序服务器上以及它收到的第一个请求时,仅针对该请求(仅 1 次),我的 Servlet 将从中获取 100 万条记录TABLE A,在ClassA的地图与这些记录,并开始填充物的ClassA,并让他们在一个Vector或ArrayList,你可能已经明白,我的Vector/ArrayList意志现在包含有代表每个对象1名亿个对象record/tupple"TableA"

OK , now come to the real and difficult part , I want this Vector/ArrayListto be stored/persisted/addedto 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/Servletsare accessing the object in memory of getting data and not hitting the database every time .

好的,现在来到真正困难的部分,我希望这Vector/ArrayListstored/persisted/added应用程序上下文或 VM 或任何其他内存存储位置(实际上我不知道),以便每次我的 JSPpages/Servlets访问对象时在内存中获取数据而不是每次都访问数据库。

采纳答案by Nicholas Bayborodin

You have to use Java Caching System(see here) or Ehcache(see here) to store data in cache, Inversion of Controlin Springalso helps in some way but not sure whether it would help to store 1 million data in heap, as heap memory is limited.

你必须使用的Java缓存系统见这里)或的Ehcache见这里的高速缓存)来存储数据,控制反转春季也有助于在某种程度上,但不知道这是否会有助于存储在堆百万的数据,如堆内存有限。

回答by Mark Bramnik

It looks like you need caching, if I get you right. I would recommend to take a look on EHcacheor Infinispanhere.

如果我没听错的话,您似乎需要缓存。我建议在这里查看EHcacheInfinispan

Hope this helps

希望这可以帮助

回答by Mukul Goel

I think you are looking for some way to cache your objects.

我认为您正在寻找某种方法来缓存您的对象。

You may want to look at ehcache

你可能想看看ehcache

or,

或者,

since you have large objects you can look at implementing Object Repository like, noDB

因为你有大对象,你可以考虑实现对象存储库,比如 noDB