for(int i=0; i<5; i++)
{
    在数据库中随机挑出一个用户给他发一条短信;
    if(有人回应)
        break;
    try
    {
        Thread.sleep(2*60*1000);
    }
    catch(Exception e)
    {
    }
}

解决方案 »

  1.   

    用java.util包中的,Timer和TimerTask类可以很容易实现看看Timer中的一个方法说明:
     void schedule(TimerTask task, Date time) 
              Schedules the specified task for execution at the specified time. 
     void schedule(TimerTask task, Date firstTime, long period) 
              Schedules the specified task for repeated fixed-delay execution, beginning at the specified time. 
     void schedule(TimerTask task, long delay) 
              Schedules the specified task for execution after the specified delay. 
     void schedule(TimerTask task, long delay, long period) 
              Schedules the specified task for repeated fixed-delay execution, beginning after the specified delay. 
      

  2.   

    谁有应用TimerTask类的例子代码么?
      

  3.   

    来个简单的:synchronized("TwoMin")
    {
        "TwoMin".wait(120000);
    }//do something you want
      

  4.   

    int delay = 5000;   // delay for 5 sec.
        int period = 1000;  // repeat every sec.
        Timer timer = new Timer();
        
        timer.scheduleAtFixedRate(new TimerTask() {
                public void run() {
                    // Task here ...
                }
            }, delay, period);