Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Retry mechanism..Urgent!  RSS feed

Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm developing an application that interacts with database. Whenever my custom code gets a notification(from some other database or application), I need to invoke some methods. These methods are API's that interact with database.
My problem is that if database is down, my custom code has to wait for some sleeptime, say for 10 mins. And then retry again to connect to database, if succeds then proceed else throw error and get out.
How do I implement this sleeping - retry mechanism? Please help me in this .
Thanks in advance
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm surprised you haven't gotten an answer from some of the smarter folks here, so I'll give a try. Look into starting a new thread for your retry logic. It can wait the ten minutes, then wake up and try the operation again. Consider the Command Pattern for putting all the logic that you want to try and retry into a Command class. Consider the Active Object pattern to handle a queue of Commands. I haven't been able to find a clear example of Active Object this morning, but the one I'm thinking of looped through a set of queued commands each of which had a "execute me at this time" variable. If the time had come, it removed and executed the command, else it left the command there to re-inspect the next time through.
Any time you spawn an operation on a new thread, you may have to figure out how to get the results back to the original requester. Consider Listener or Publish Subscribe for that. I have a page on Messaging that gets into some of the asynchronous issues.
[ August 26, 2003: Message edited by: Stan James ]
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!