lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Hostetter <hossman_luc...@fucit.org>
Subject Re: [jira] Updated: (LUCENE-665) temporary file access denied on Windows
Date Thu, 21 Sep 2006 19:10:56 GMT

The recurring pattern seems to be...

  ResultType methodName(ArgType args) throws ExceptionType {
    int trialsSoFar = 0;
    long maxTime = System.currentTimeMillis() + maxTotalDelay;
    Exception error = null;
    while (waitAgain(maxTime, trialsSoFar++, error)) {
      try {
        return super.methodName(args);
      } catch (ExceptionType e) {
        error = e;
      }
    }
    return super.methodName(args);
  }

...where the waitAgain method seems to take in more args then it really
needs (error is completley unused, and trialsSoFar is only need to know if
we are on the first trial)

There may be a subltety i'm missing here, but it seems like this might be
more clearly (and susinctly) expressed with something like...

  ResultType methodName(ArgType args) throws ExceptionType {
    long maxTime = System.currentTimeMillis() + maxTotalDelay;
    while (true) {
      try {
        return super.methodName(args);
      } catch (ExceptionType e) {
        if (maxTime < System.currentTimeMillis()) throw e
      }
      wait(maxTime);
    }
  }

...where the wait method also get's simpler...

  static void wait(long maxTime)
    long moreTime = maxTime - System.currentTimeMillis();
    long delay = Math.min(moreTime, intervalDelay);
    try {
      Thread.sleep(delay);
    } catch (InterruptedException e1) {  /* NOOP */  }
  }

...but i haven't tried this, and as i said: there may be some subltety of
your approach that i'm missing.



-Hoss


---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org


Mime
View raw message