在新线程中运行thrift无法捕获异常

时间:2017-12-06 09:44:00

标签: java multithreading exception thrift

我在这样的线程中运行thrift:

public static void start() {        
    Runnable simple = new Runnable() {
        public void run() {

            TProcessor tprocessor = new MessageForwardsService.Processor<MessageForwardsService.Iface>(new MessageForwardsRpcInterface());

            try {
                simple(tprocessor);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    };

    Thread t = new Thread(simple);
    t.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {  

        @Override  
        public void uncaughtException(Thread t, Throwable e) {  
            System.out.println("Thread  uncaughtExceptionHandler catch a Exception**************************************************><><><><><><><><><<><><><><><");  
            System.out.println(e.getMessage()); 
            e.printStackTrace();
        }  
    }); 
    t.start();
}

@SuppressWarnings("rawtypes")
public static void simple(MessageForwardsService.Processor processor) {
    try {
    TServerTransport serverTransport = new TServerSocket(WhrPublicConstants.RPC_PORT,2000);
        TServer server = new TSimpleServer(new Args(serverTransport).processor(processor));

        System.out.println("Starting the rpc server... on port:"+WhrPublicConstants.RPC_PORT);
        server.serve();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

rpc方法是:

    @Override
    public int emulateDevice( String msg) throws TException {
        throw new RuntimeException("just test throw exception");
        return 0;
    }

在客户端,我可以得到错误:     org.apache.thrift.transport.TTransportException

但是在thrift服务器端,我无法像上面那样捕获异常。

谁能帮帮我?感谢。

0 个答案:

没有答案