0

I have 10000+ records in a file. I read the file and keep the records in ArrayList, my web application reads the arraylist frequently.

I only perform reading operation on arraylist.

However the performance of web application is slow.

Will it be better to keep the data from file in Database and read from database.

Or is there any other collection that I can use.

3
  • Reading from database will definitely decrease the performance than ArrayList if you access the list very frequently. Can you give some details about how you access that array, iterate through the list or access it by index? Iteration is costlier than index access. Commented Aug 31, 2015 at 3:00
  • @Selvaraj thanks I m iterating the list Commented Aug 31, 2015 at 3:05
  • iteration will takes time much. Can you access the array by index. Commented Aug 31, 2015 at 3:07

1 Answer 1

1

With an ArrayList<MyRecord> you don't have a good lookup method, so your code is likely doing sequence searches whenever you need to find a record.

If you only ever lookup by one value, e.g. name, then change to HashMap<String, MyRecord>. This will allow direct lookup without need for sequence search.

If you lookup by various values, keep the ArrayList<MyRecord> around, but build multiple maps, one for each lookup field (or set of fields).

The maps are basically the same as indexes in a database.

Now, if data is updated, things are very different. Does an update require you to write the entire file again, immediately? What if the program dies halfway through a write? Databases have built-in guards that help prevent data loss, and will also allow sharing the data among multiple programs running at the same time.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @Andreas The file gets updated periodically and the application reads the file and updates the arraylist. I need arraylist only for reading the data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.