gpt4 book ai didi

java - Thrift TServer 服务不返回主线程

转载 作者:行者123 更新时间:2023-12-02 07:11:37 26 4
gpt4 key购买 nike

以下是我如何实现thrift服务器,但在serve()调用后它不会返回到主Therad。

public class ThriftServerRunner implements Runnable {
private int thriftServerPort;
public ThriftServerRunner(int thriftServerPort, LogWriter logWriter) {
this.thriftServerPort = thriftServerPort;
}
@Override
public void run() {
try {
SetupThriftServer();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

private void SetupThriftServer() throws Exception {
try {
TServerSocket serverTransport = new TServerSocket(this.thriftServerPort);
ThriftService.Processor<ThriftService.Iface> processor = new ThriftService.Processor(new ThriftServiceImpl());
TServer server = new TThreadPoolServer(new TThreadPoolServer.Args(serverTransport).processor(processor));
server.serve();
} catch (TTransportException e) {
e.printStackTrace();
}
}
}

最佳答案

您确实调用 start() 来启动线程(这将创建一个新线程,然后从这个新线程调用对象 run() 函数),并且不是 run() (它只会从您当前所在的同一线程运行 run()),对吗?

serve() 并不意味着返回,除非您停止服务器(从另一个线程)。

关于java - Thrift TServer 服务不返回主线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15438155/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com