wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets 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: 430

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: 8836

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.

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
wood burning stoves
subject: Pause/ Sleep for n seconds in a JEE enviorenment
Similar Threads
weblogic server state using embedded form of WLST
does gc still have a chance to do its job if i kill the java process
Thread Wait Issue
JUnit Test Cases
URLyBird: Please Help! Non-deterministick error with database record reading