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>();
Using TreeSet may be right for you. It provides O(log(n)) access performance.