Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Pause/ Sleep for n seconds in a JEE enviorenment

 
Fahim Farook
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 785
7
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Pie
Posts: 9264
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic