• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Pause/ Sleep for n seconds in a JEE enviorenment

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Bartender
Posts: 1357
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic