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.
I have web application deployed on weblogic. This web application has a servlet which tries to connect to a DB and if it fails it will wait/pause/sleep for some configured period of time and try to connect to the DB again. (Actually it will wait and try N times, exponentially, and if all the attempts fail, it will return a FAILURE response).
In order to wait/ pause between two attempts, I used
But in the production environment where 8 weblogic managed servers are running, I found that Thread.sleep() is not reliable. It sleeps more than the configured time.
Is there any workaround for this?
Here's my code. Please note that I'm calling this from a managed server enlivenment.
If I were you, I'd prefer not to use a similar approach; instead, I would send a response to the client -eventually, an error message - as soon as possible.
In my experience, I learnt that the faster the appserver responds, the better; I'd let the client have the responsability to retry N times - with an incremental delay between retries (that seems to me a good idea, to wait for a growing time..
but on client side.)
As far as I know, an appserver uses a limited (in size) thread pool for handling web request; you're keeping busy one of them for longer than the needed time, and you may run
out of availbale thread in the pool. With the risk to get the whole app not working.