以下是我实现thrift
服务器的方式,但在调用后它不会返回到 main therad serve()
。
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();
}
}
}