【问题标题】:Netty 4, use the current thread for an HTTP clientNetty 4,将当前线程用于 HTTP 客户端
【发布时间】:2015-05-15 00:24:00
【问题描述】:

我想使用 Netty 4 编写一个 HTTP 客户端,它不需要创建任何额外的线程。

我从 HttpSnoopClient 开始工作并尝试替换:

EventLoopGroup group = new NioEventLoopGroup();

与:

EventLoopGroup group = new NioEventLoopGroup(1, new Executor() {
    public void execute(Runnable command) {
        command.run();
    }
});

但是程序挂了:

ChannelFuture f = bootstrap.connect(host, port);

Netty in Action 一书没有提到这种可能性,但我有一些希望(在这里和那里设置适当的回调或侦听器......)。现在我想知道这是否可能。

提前感谢您的任何提示。

【问题讨论】:

    标签: netty


    【解决方案1】:

    不,这是不可能的,因为线程将用于阻塞选择器,因此您至少需要一个额外的线程。

    【讨论】:

    • 感谢您的回答(以及写这本书:非​​常有启发性,非常有帮助)!
    猜你喜欢
    • 2014-09-19
    • 1970-01-01
    • 2016-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-19
    • 2021-12-05
    • 1970-01-01
    相关资源
    最近更新 更多