9 Replies Latest reply: Dec 28, 2011 1:48 AM by Darryl Burke RSS

    Swing - Timeout Mechanism

    869960
      I would like to implement timeout mechanism by while-loop. Here is my code:
      Code:
      -----
      Date dateStart = new Date();
      Thread thread = new Thread(objRunnable);
      thread.start();
      Date dateCheck = new Date();
      while(!objRunnable.isFinished()
      && (dateCheck.getTime() - dateStart.getTime() < 2000)) {
           dateCheck = new Date();
      }
      Date dateEnd = new Date();

      -----

      However, the result of dateEnd.getTime() - dateStart.getTime() sometimes is bigger than 2000.

      What is wrong with my code?