When ever we dealing with huge amount of data,we always find difficult achieving good performance.I have faced similar issue. To solve i followed simple below techniques which helped me to see good improvement in java performance
1) First and most important is writing efficient code.
What is efficient code means ?
Avoid unnecessary iterations which can be avoided by writing conditional blocks.Make sure it is really needed to execute that loop all the time or only for special cases.
Use break; statement when it is necessary.When ever in loop if you are looking for particular element then break the loop once you found the element.
Do not extract same element twice.For example you are looking for particular element in loop and you found it then try to pass it all the method where ever it is needed,do not extract it again.
2) Use frameworks, third party jars.
Example:Spring frame works take care life cycle of beans,it will load beans when container loads which will make application light weight.
Proved third party jars will already have well tested and efficient code which will save your time as well as it improve performance,but make sure using third party library is really needed.
3) Avoid unnecessary logging which means writing log statement in loop,duplicate logs
4) Always measure response time,which helps you to write efficient code.
5) Do not hit data base several times for single action,Which can avoided by writing DB Stored procedure,functions.
Example:If user action has end up having insert/update and data retrieval then pass all data as input parameters to DB procedure perform insert/update and execute select query pass back result set as out parameter from DB procedure.
6) Always tune DB queries,which means use joins carefully when ever data is high.Use DB indexes and use indexed columns for joins.Avoid outer joins.
7) Mostly importantly for Data retrieval if you are using JDBC then set fetch size.
By default, when Oracle JDBC executes a query, it receives the result set 10 rows at a time from the database cursor. This is the default Oracle row-prefetch value. You can change the number of rows retrieved with each trip to the database cursor by changing the row-prefetch value.
Connection connection = DriverManager.getConnection(
Statement statement = connection.createStatement();
// configure the fetch size
ResultSet resultSet = statement.executeQuery(
Hope these points helps making difference:)