java-dev@lucene.apache.org
[Top] [All Lists]

Re: [jira] Updated: (LUCENE-665) temporary file access denied on Windows

Subject: Re: [jira] Updated: (LUCENE-665) temporary file access denied on Windows
From: Chris Hostetter
Date: Thu, 21 Sep 2006 12:10:56 -0700 PDT
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@xxxxxxxxxxxxxxxxx
For additional commands, e-mail: java-dev-help@xxxxxxxxxxxxxxxxx

<Prev in Thread] Current Thread [Next in Thread>