[concurrency-interest] Future.isCompletedNormally Future.isCompletedAbnormally

Chris Purcell chris.purcell.39 at gmail.com
Mon Mar 9 05:10:15 EDT 2015


Possible alternative implementation:

default boolean isDoneSuccessfully() {
  try {
    get(this, 0, SECONDS);
    return true;
  } catch (CancellationException
      | ExecutionException
      | TimeoutException e) {
    return false;
  } catch (InterruptedException e) {
    currentThread().interrupt();
    return false;
  }
}

My understanding of hotspot optimisation (limited) suggests (a) the
InterruptedExceptions, CancellationExceptions and TimeoutExceptions will be
interned, (b) the optimiser is more likely to trigger (and hopefully kill
the exceptions entirely?) if we keep this small.

The benefit of a default implementation over doing this by hand, apart from
discoverability and overrideability, is that this is more likely to be
optimised, being a common method.

(I'm assuming interruptions only occur for incomplete futures. I think
that's a valid assumption, otherwise there's no non-blocking way to get a
future's result.)

Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20150309/a1c43d17/attachment.html>


More information about the Concurrency-interest mailing list