optimize java code to avoid consuming too much memory
$30-250 AUD
Paid on delivery
You need to optimise the following code as it will consume more and more memory after startup.
It can only run for several hours on the server and the server will run out of memory for the java heap space.
final int BATCH_SIZE = 3000;
Connection dbConnection = null;
PreparedStatement preparedStatement = null;
String connectionString = [login to view URL]("ConnectionString")+"&rewriteBatchedStatements=true";
try {
dbConnection= [login to view URL](connectionString);
[login to view URL](false);
int sleepCount = 1;
StringBuilder offerString = new StringBuilder();
while (true) {
ArrayList<MessageQueueEntity> queueItems = [login to view URL]();
Iterator<MessageQueueEntity> itemIter = [login to view URL]();
while ([login to view URL]()) {
try{
MessageQueueEntity message = [login to view URL]();
OfferEntity offer = processOffer(message);
if(sleepCount % BATCH_SIZE == 1) {
[login to view URL]("INSERT INTO offer " +
"(asn,itemCondition,amount,amount_bookepot, " +
"timeofPolling,timeofUpdate,updated) VALUES ");
}
[login to view URL]("('" + [login to view URL]() + "', ");
[login to view URL]("'" + [login to view URL]() + "' , ");
[login to view URL]([login to view URL]() + ", ");
[login to view URL](offer.getAmount_Bookepot() + ", ");
[login to view URL]("'" + [login to view URL]() + "', ");
[login to view URL]("CURRENT_TIMESTAMP" + ",");
[login to view URL]("1" + ")");
if(sleepCount % BATCH_SIZE !=0) {
[login to view URL](" , ");
}else{
[login to view URL](" ON DUPLICATE KEY UPDATE amount= VALUES(amount), " +
"amount_bookepot= VALUES(amount_bookepot), " +
"updated = 1;");
preparedStatement = (PreparedStatement) [login to view URL]([login to view URL]());
[login to view URL]();
[login to view URL]();
[login to view URL](0);
[login to view URL](BATCH_SIZE+" offers were inserted into offer table!");
}
sleepCount++;
}catch (Exception e){
[login to view URL]();
}
} //inner loop
if ([login to view URL]()) break;
}//whole loop
} catch (Exception e) {
[login to view URL]([login to view URL]());
//[login to view URL]();
} finally {
}
Project ID: #13076567
About the project
13 freelancers are bidding on average $97 for this job
Amazon Web Services: Lambda, API Gateway, EC2, Load Balancers, RDS, Elastic Beanstalk, Elastic File System, IAM, VPC, Security Groups, Cloud Formation,, S3, CLoudFront, Redshift, Route 53, Cloud Watch, Kinesis, SNS, SQ More
One of the option is to increase java heap size. If it doesn't solve the problem then we can optimize the code for you
I am an experienced Java developer. I will optimize software for your. Feel free to contact me for further discussion. Regards, Moeen Ahmed
Hi, I am a software developer with 8+ years of experience in Java/J2EE development. My specialization is in Memory and CPU profiling using tools like Yourkit, JProfiler, and VisualVM I believe I can really help y More
Hello, i found the bad code snippet that make the memory overflow , please contact me More
We are PR Technologies. We have a team of experienced Java developers, who works together and contribute to Develop Quality Products. So, if you show some trust, then we will guaranteed for a Best products. Thanks & Re More
Hi, I am an IT engineer. Hi have much experience in java I'm quite sure I can find the memory leaks and fix them successfully. I've faced many issues like that in the past, where my memory was just increasing until it More