开发者

connecting database in regular interval

I have a situation where I have to check for a value in a database say aValue. If aValue is availabe then do process aValueProce开发者_运维百科ss(). 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.


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();
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜