This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.
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.