-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move to Java 8 #84
Move to Java 8 #84
Conversation
I ran the built in benchmark and got the following results:
Not sure how much it can be trusted. Right not it looks like using Java8 futures is a slight optimization, but not by a large margin. At least this might indicate that there is no performance regression. |
CallbackSettableFuture<T> newFuture = new CallbackSettableFuture<>(future); | ||
future.addListener(newFuture, executor); | ||
return newFuture; | ||
return future.thenApplyAsync(Function.identity(), executor); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if this is correct - will exceptions run on this executor? How could I make that happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs and a quick empirical test indicates that the executor supplied to thenApplyAsync
is not used for exceptions.
The handleAsync
method seems to cause both normal values and exceptions to be run on the supplied executor.
E.g.
return future.handleAsync((v, e) -> {
if (v != null) {
return v;
} else {
throw new CompletionException(e);
}
}, executor);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even better:
return future.whenCompleteAsync((v, e) -> { }, executor);
public ListenableFuture<List<T>> unwrapList(ListenableFuture<List<GetResult<T>>> future) { | ||
return Utils.transform(future, listResultUnwrapper); | ||
public CompletionStage<List<T>> unwrapList(CompletionStage<List<GetResult<T>>> future) { | ||
return future.thenApplyAsync(listResultUnwrapper, Utils.SAME_THREAD_EXECUTOR); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use simple thenApply(...)
instead.
return Utils.transform(future, listResultDecoder); | ||
public CompletionStage<List<GetResult<T>>> decodeList( | ||
CompletionStage<List<GetResult<byte[]>>> future) { | ||
return future.thenApplyAsync(listResultDecoder, Utils.SAME_THREAD_EXECUTOR); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above.
try { | ||
connectFuture().toCompletableFuture().get(waitTime, unit); | ||
} catch (final InterruptedException | ExecutionException e) { | ||
throw new RuntimeException(e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should you handle interrupter correctly?
This is a continuation of PR #80 with some additional changes