I am new to Java. I tried to write a program to check database status (overloaded or not).
CODE:
package com.test.service;
import java.util.LinkedList;
import java.util.List;
public class PersonImpl {
public PersonService personService;
public void InsertPersonDetails(Person person) {
if(personService.isOverLoaded()) {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
} else {
//pass control to dao
}
}
}
Here I will get boolean
from isOverLoaded
. If isOverLoaded
value is yes then we should stop passing control to dao for few seconds and then check isOverLoaded
method again.
Help would be appreciated :)
I would go for an ScheduledExecutorService. Create a thread and as long as isOverloaded()
returns true re schedule the execution.