public interface AsyncContext
javax.servlet.AsyncContext in the Servlet 3.0.
An AsyncContext is stated by a call to RpcContext.startAsync().
The demo is com.alibaba.dubbo.examples.async.AsyncConsumer
and com.alibaba.dubbo.examples.async.AsyncProvider
| 限定符和类型 | 方法和说明 |
|---|---|
boolean |
isAsyncStarted() |
void |
signalContextSwitch()
Signal RpcContext switch.
|
void |
start()
change the context state to start
|
boolean |
stop()
change the context state to stop
|
void |
write(Object value)
write value and complete the async context.
|
void write(Object value)
value - invoke resultboolean isAsyncStarted()
boolean stop()
void start()
void signalContextSwitch()
public class AsyncServiceImpl implements AsyncService {
public String sayHello(String name) {
final AsyncContext asyncContext = RpcContext.startAsync();
new Thread(() -> {
// right place to use this method
asyncContext.signalContextSwitch();
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
asyncContext.write("Hello " + name + ", response from provider.");
}).start();
return null;
}
}
Copyright © 2011–2021 The Apache Software Foundation. All rights reserved.