2013-03-15 2 views
0

다음은 thrift 서버를 구현 한 방법이지만 serve() 호출 후에 메인 therad로 돌아 가지 않습니다.Thrift TServer 서브가 주 스레드로 돌아 가지 않습니다.

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(); 
    } 
    } 
} 

답변

2

당신은 (새로운 스레드를 생성 한 후 객체이 새로운 스레드에서 run() 함수를 호출합니다) 스레드를 시작 start()를 호출 할, 그리고 run() (당신과 같은 스레드에서 run()을 실행할 현재), 맞지?

serve()은 (다른 스레드에서) 서버를 중지하지 않는 한 반환하지 않습니다.

관련 문제