小编ecl*_*pse的帖子

如何做非阻塞IO?

我正在使用Undertow创建一个简单的应用程序.

public class App {
    public static void main(String[] args) {
        Undertow server = Undertow.builder().addListener(8080, "localhost")
                .setHandler(new HttpHandler() {

                    public void handleRequest(HttpServerExchange exchange) throws Exception {
                        Thread.sleep(5000);
                        exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain");
                        exchange.getResponseSender().send("Hello World");
                    }

                }).build();
        server.start();
    }
}
Run Code Online (Sandbox Code Playgroud)

我打开浏览器选项卡,localhost:8080然后打开第二个选项卡localhost:8080

这次第一个标签将等待5秒,第二个标签将等待10秒

为什么会这样?

java undertow

10
推荐指数
3
解决办法
8078
查看次数

标签 统计

java ×1

undertow ×1