[英]How to monitor database connection in java?
i have created web application using java. 我已经使用Java创建了Web应用程序。 In that i am using tomcat server and SQL server.
在那我正在使用tomcat服务器和SQL服务器。 I need to implement watch dog service for monitoring database connection and server connection.
我需要实现监视程序服务以监视数据库连接和服务器连接。 I mean if database is not connecting or tomcat server is down then i need to write a code for send a alerting mail to my mail id.
我的意思是,如果数据库未连接或tomcat服务器已关闭,那么我需要编写代码以向我的邮件ID发送警报邮件。
pls someone help me... 请有人帮我...
You can create a separate thread to monitor the DB connection. 您可以创建一个单独的线程来监视数据库连接。 While starting the server invoke that thread.
启动服务器时,调用该线程。 If db connection failed means send mail from that threat.
如果数据库连接失败,则表示从该威胁发送邮件。
Example : 范例:
boolean isDBConnected,isServerConnected;
while(true){
isDBConnected=checkDBConnection();
isServerConnected=checkServerStatus();
if(isDBConnected && isServerConnected){
Thread.sleep(100);
}else{
sendMail();
break;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.