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.
java等待几秒 java暂停几秒
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
javacv排除包
java应用故障的排查 常用工具: 1.jps jps命令用来输出JVM虚拟机进行的一些信息,优点类似于Linux的PS命令,可以列出虚拟机当前正在执行的进程,并显示器主类
javacv排除包 java应用故障的排查工具 JVM Java 内存空间