This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes BEA/Weblogic and the fly likes Pause/ Sleep for n seconds in a JEE enviorenment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Products » BEA/Weblogic
Bookmark "Pause/ Sleep for n seconds in a JEE enviorenment" Watch "Pause/ Sleep for n seconds in a JEE enviorenment" New topic

Pause/ Sleep for n seconds in a JEE enviorenment

Fahim Farook

Joined: Mar 20, 2011
Posts: 12
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.

Claude Moore
Ranch Hand

Joined: Jun 24, 2005
Posts: 700

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.

Joe Ess

Joined: Oct 29, 2001
Posts: 9150

Is there some reason this database is not available? You can configure Weblogic connection pools to test connections before they are allocated and prune expired connections.

[How To Ask Questions On JavaRanch]
I agree. Here's the link:
subject: Pause/ Sleep for n seconds in a JEE enviorenment
jQuery in Action, 3rd edition