I am working on a java application(Batch Process) and we have to use some third party API's (No Option to change it) related to the Database.It is causing out of memory after every 25000 updates and the total records are 5 million or so. I used the JProfiler to find out that the out of memory is caused by the third party API only.Since the application is in the production already we really cannot risk to change that third party API at any cost so we have to do some work around.
What is the best work around in this scenario? I am thinking to create separate thread in the below mentioned code which will do the first 20000 updates and as soon as this thread dies all the objects associated with this will also die and hence the new thread will be a fresh start and again the new thread will do 20000 updates or something like that.
If you have encountered such kind of problem in the past please help me and if possible write a pseudo code or sample code for it.
my current code looks like this which I am thinking to add the java threads:
public static void main(String [] args){
*ResultSet* rs (rs has all the records e.g. 5 millions)
long count=0;
while (rs.next()){
doUpdate();
count++;
*//the code fails if the count reaches to 25000*
}
}