optimize java code to avoid consuming too much memory

In Progress Posted 7 years ago Paid on delivery
In Progress 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 {

}

Amazon Web Services Java

Project ID: #13076567

About the project

13 proposals Remote project Active 7 years ago

13 freelancers are bidding on average $97 for this job

dirisalagopal

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

$99 AUD in 0 days
(36 Reviews)
5.7
Javagurupk

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

$50 AUD in 2 days
(62 Reviews)
5.5
moeenahmed21

I am an experienced Java developer. I will optimize software for your. Feel free to contact me for further discussion. Regards, Moeen Ahmed

$50 AUD in 3 days
(16 Reviews)
4.5
dharamdaring

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

$111 AUD in 3 days
(17 Reviews)
4.3
abdelrahman1989

Hello, i found the bad code snippet that make the memory overflow , please contact me More

$66 AUD in 3 days
(6 Reviews)
3.4
PRTechno7868

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

$44 AUD in 2 days
(7 Reviews)
3.4
LyubomirT

Hello, I've reviewed the code and the problem is easy to identify, I guess you know the cause is the cyclic loop. For the correct optimization it seems that the best way would be to apply a design pattern called Obser More

$190 AUD in 4 days
(4 Reviews)
2.9
fatma19

hi, i geuss this job is mine.I m a computer science engineering student . i worked a lot with java and i made many apps using netbeans and eclipse .I am Oracle Certified Associate Java SE 7. i can accomplish this task More

$50 AUD in 0 days
(7 Reviews)
2.6
ricardoacmaia

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

$100 AUD in 3 days
(0 Reviews)
0.0
vishlkjain

I would love to do this job.

$111 AUD in 3 days
(0 Reviews)
0.0
NightTerror6

A proposal has not yet been provided

$133 AUD in 3 days
(0 Reviews)
0.0