tags:

views:

31

answers:

1

I have a situation where I have to check for a value in a database say aValue. If aValue is availabe then do process aValueProcess(). If the value is not available, I only can wait 30 min, and needs to check the database for value for every 10 minutes (3 times). If it exceeds 30 min exit the program.

Can anybody give me the logic for the best way to do it. Any help is appreciated.

+1  A: 

Here is something I hashed that should at least show you the logic (note I do mostly c# so you will probably have to change the functions.

    val aValue = aValueProcess();
    int attempts = 0;

    //Wait 10 minutes and try again if value is null and we have not tried 
    //3 times (30 minutes of trying)
    while(aValue == null && attempts < 3)
    {
      thread.sleep(600000); //10 minutes in milliseconds
      attempts += 1;
      aValue = aValueProcess();
    }
kniemczak