File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Tomcat and the fly likes How to monitor a email resource Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "How to monitor a email resource" Watch "How to monitor a email resource" New topic

How to monitor a email resource

Alex S.K. Lau

Joined: Mar 14, 2013
Posts: 2
How to monitor an email resource defined in web.xml to know if connection has or can be established with the smtp server? My email server come on and off so I need to configure multiple email resource poitning to different smtp server but I do not want to wait for connection timeout in my application before fail over to another (This just takes too long). I want to be able to monitor the connection and choose an active one without waiting.
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

But the only way to find out whether a mail server (or any kind of server for that matter) is active is to try to connect to it. And that unavoidably requires waiting a decent amount of time before you conclude it isn't active. So there isn't any way to avoid waiting for a timeout.

You may imagine some scheme where you have some agent which is continuously testing to see if a server is active. But that doesn't solve your problem either, since knowing that the server was active two seconds ago tells you nothing about whether it's active right now. And you may find yourself trying to connect with the agent while it's in the process of waiting for a timeout to expire -- what are you going to do then?

So if your actual problem is that having to wait for timeouts is affecting your application's response time in a bad way, then I suggest you redesign your application so that it doesn't connect to the mail server itself. Have it send a message to some other process which is responsible for dealing with your unreliable servers and sending the mail when one is available.
I agree. Here's the link:
subject: How to monitor a email resource
jQuery in Action, 3rd edition