Reputation: 121
i have created web application using java. In that i am using tomcat server and SQL server. 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.
pls someone help me...
Upvotes: 0
Views: 1994
Reputation: 10069
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;
}
}
Upvotes: 1