This is an automated email from the ASF dual-hosted git repository. liujun pushed a commit to branch master-hsf in repository https://gitbox.apache.org/repos/asf/dubbo.git
commit 12b3fc483a2fc5a39c85f8da77931ec0b06944bf Author: beiwei.ly <[email protected]> AuthorDate: Wed Nov 27 21:16:09 2019 +0800 avoid busy wait when executor is null --- .../remoting/exchange/support/DefaultFuture.java | 23 +++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java index 0abecf2..06fd562 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/exchange/support/DefaultFuture.java @@ -264,17 +264,22 @@ public class DefaultFuture extends CompletableFuture<Object> { if (future == null || future.isDone()) { return; } + if (future.getExecutor() != null) { - future.getExecutor().execute(() -> { - // create exception response. - Response timeoutResponse = new Response(future.getId()); - // set timeout status. - timeoutResponse.setStatus(future.isSent() ? Response.SERVER_TIMEOUT : Response.CLIENT_TIMEOUT); - timeoutResponse.setErrorMessage(future.getTimeoutMessage(true)); - // handle response. - DefaultFuture.received(future.getChannel(), timeoutResponse, true); - }); + future.getExecutor().execute(() -> notifyTimeout(future)); + } else { + notifyTimeout(future); } } + + private void notifyTimeout(DefaultFuture future) { + // create exception response. + Response timeoutResponse = new Response(future.getId()); + // set timeout status. + timeoutResponse.setStatus(future.isSent() ? Response.SERVER_TIMEOUT : Response.CLIENT_TIMEOUT); + timeoutResponse.setErrorMessage(future.getTimeoutMessage(true)); + // handle response. + DefaultFuture.received(future.getChannel(), timeoutResponse, true); + } } }
