Skip to content

Instantly share code, notes, and snippets.

@qsLI
Created January 15, 2018 06:27
Show Gist options
  • Save qsLI/db4cd7b50545292175b460e399b3fedb to your computer and use it in GitHub Desktop.
Save qsLI/db4cd7b50545292175b460e399b3fedb to your computer and use it in GitHub Desktop.
timeout scanner
private static class RemotingInvocationTimeoutScan implements Runnable {
public void run() {
while (true) {
try {
for (DefaultFuture future : FUTURES.values()) {
if (future == null || future.isDone()) {
continue;
}
if (System.currentTimeMillis() - future.getStartTimestamp() > future.getTimeout()) {
// 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);
}
}
Thread.sleep(30);
} catch (Throwable e) {
logger.error("Exception when scan the timeout invocation of remoting.", e);
}
}
}
}
static {
Thread th = new Thread(new RemotingInvocationTimeoutScan(), "DubboResponseTimeoutScanTimer");
th.setDaemon(true);
th.start();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment