简体   繁体   English

最好的方法是-在何时何地将表数据存储到java arraylist或access表中?

[英]Which is the best way to go - store table data to java arraylist or access table when and where needed?

The problem is like this: 问题是这样的:

I am retrieving latitude and longitude from a point and storing it into an agent class. 我正在从一个点检索纬度和经度,并将其存储到agent类中。 The class has the members id, latitude and longitude and assosciated functions. 该类具有成员ID,纬度和经度以及相关功能。

Now at the start of the java app, it reads all rows from a local MySQL table(having cordinate values) and stores it into an arraylist of these agent variables. 现在,在Java应用程序的开始处,它从本地MySQL表(具有坐标值)读取所有行,并将其存储到这些agent变量的数组列表中。 It then reads through this arraylist and calls necessary functions and draws a graph at the end. 然后,它读取此arraylist并调用必要的函数,并在最后绘制一个图形。

This works fine for a table of 8K - 10K rows but then for another table with about 200,000 rows, it starts giving Heap size error in java. 对于8K-10K行的表来说,这很好用,但是对于另一个约200,000行的表,它开始在Java中给出堆大小错误。

I am thinking of changing the code to access the db everytime coordinates of an agent is needed. 我正在考虑每次需要代理的坐标时更改代码以访问数据库。 This should reduce the memory required right? 这样应该减少所需的内存吧? However, there are many loops using the Iterator of this agent ArrayList. 但是,有很多循环使用此agent ArrayList的Iterator I am still in a fix on how to handle that. 我仍然在解决该问题。

So which would be a better option - reading from the table everytime or proceed as it is and increase the java memory allocation? 因此,哪个更好的选择-每次从表中读取数据,还是按原样进行并增加Java内存分配? Thanks for reading. 谢谢阅读。

try to only load data as you need it. 尝试仅根据需要加载数据。 We don't have very much information, but I am assuming there is no need for the user to see/interact with all 10,000 data points at once. 我们没有太多信息,但是我假设用户不需要一次查看/交互所有10,000个数据点。 Besides the physical limitations of the size of the device screen, realistically a user will just be overwhelmed with that much information. 除了设备屏幕尺寸的物理限制之外,实际上,用户会被这么多的信息所淹没。

I would try implementing a paging system. 我将尝试实现分页系统。 Again, I have no idea what you are using the Agent class for, but try to only load as many Agent s as you are showing to the user. 同样,我不知道您正在使用Agent类做什么,但是尝试仅加载与显示给用户一样多的Agent

Your strategy has serious drawback: big amount of data is read from disk, then stored in database's memory, sent to java app and it finally placed in JVM's memory. 您的策略有一个严重的缺点:从磁盘读取大量数据,然后将其存储在数据库的内存中,发送给Java应用程序,最后将其放置在JVM的内存中。 This takes much time and resources. 这需要很多时间和资源。

Use cursors, then you 'll be able to read from db and iterate on resultset in java app at the same time and JVM won't have to allocate so much memory. 使用游标,那么您将可以同时从db中读取数据并在java应用程序的结果集中进行迭代,并且JVM不必分配太多内存。

Some documentation: 一些文档:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM