对于可以增长到数千行的数据是否建议使用哈希集?

发布于 2024-12-15 01:05:12 字数 1135 浏览 1 评论 0原文

我正在维护一个旧的 J2EE Web 应用程序,并且一直收到有关修复其性能的投诉。在分析它的数据架构时,我意识到程序员有哈希集来存储增长到数千行的表值。考虑到 java API 关于哈希集的说法,我真的认为这是一个非常非常糟糕的主意,特别是当数据库表按某些属性排序时,这就是性能下降的原因,但我需要应用一些解决方案为了减轻这种性能影响,虽然我正在考虑几种选择,但我想知道是否可以使用一些其他需要较少计算来保存数据的数据结构。下面是要映射到数据库的类之一的摘录。请记住,还有大约 12 名以上的成员,包括此处显示的成员:

    /* Hibernate attribute mapping */

private Set<Supplier> suppliers = new HashSet<Supplier>(); 

private Set<Customer> customers = new HashSet<Customer>(); 

private Set<Tarif> tarif = new HashSet<Tarif>(); 

private Set<Contribution> contributions = new HashSet<Contribution>();

private Set<Premium> premiums = new HashSet<Premium>();

private Set<Alert> alerts = new HashSet<Alert>(); 

private Set<CustomerInvoice> customerInvoices = new HashSet<CustomerInvoice>();

private Set<Monitoring> monitorings = new HashSet<Monitoring>();    

private Set<Criterions> criterions= new HashSet<Criterions>();

private Set<User> registeredUsers= new HashSet<User>();

private Set<Cost> costs= new HashSet<Cost>();

I am maintaining an old J2EE web application and been getting complaints about fixing it's performance. On analysing it's data architecture, I realised that the programmer(s) is/have hash sets to store table values that grow to thousands of rows. Considering what the java API says about the hashset I really think this is a really really bad idea, especially when the database tables are ordered by some attribute(s) so this is where the performance hit is coming from but I need to apply some solution to mitigate this performance hit and whilst I am thinking of several options, I'd like to know if I can use some other data structure that requires less computation to hold the data. Below is an excerpt of one of the classes to be mapped to the database. bear in mind that there's about another 12+ members including what's shown here:

    /* Hibernate attribute mapping */

private Set<Supplier> suppliers = new HashSet<Supplier>(); 

private Set<Customer> customers = new HashSet<Customer>(); 

private Set<Tarif> tarif = new HashSet<Tarif>(); 

private Set<Contribution> contributions = new HashSet<Contribution>();

private Set<Premium> premiums = new HashSet<Premium>();

private Set<Alert> alerts = new HashSet<Alert>(); 

private Set<CustomerInvoice> customerInvoices = new HashSet<CustomerInvoice>();

private Set<Monitoring> monitorings = new HashSet<Monitoring>();    

private Set<Criterions> criterions= new HashSet<Criterions>();

private Set<User> registeredUsers= new HashSet<User>();

private Set<Cost> costs= new HashSet<Cost>();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹿童谣 2024-12-22 01:05:12

使用 TreeSet 可能适合您。它提供 O(log(n)) 访问性能。

Using TreeSet may be right for you. It provides O(log(n)) access performance.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文