Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.shiyq.thrift.demo; import org.apache.thrift.TProcessor; import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TCompactProtocol; import org.apache.thrift.server.TNonblockingServer; import org.apache.thrift.server.TServer; import org.apache.thrift.server.TSimpleServer; import org.apache.thrift.server.TThreadPoolServer; import org.apache.thrift.transport.TNonblockingServerSocket; import org.apache.thrift.transport.TServerSocket; import org.apache.thrift.transport.TTransportException; /** * * @author shiyq */ public class HelloServerDemo { public static final int SERVER_PORT = 8090; public void startServer() { try { System.out.println("HelloWorld TSimpleServer start ...."); TProcessor tprocessor = new HelloWorldService.Processor<HelloWorldService.Iface>(new HelloWorldImpl()); TServerSocket serverTransport = new TServerSocket(SERVER_PORT); //TServer.Args tArgs = new TServer.Args(serverTransport); //TNonblockingServerSocket serverTransport = new TNonblockingServerSocket(SERVER_PORT); //TNonblockingServer.Args tArgs = new TNonblockingServer.Args(serverTransport); TThreadPoolServer.Args tArgs = new TThreadPoolServer.Args(serverTransport); tArgs.processor(tprocessor); tArgs.protocolFactory(new TBinaryProtocol.Factory()); //tArgs.protocolFactory(new TCompactProtocol.Factory()); // tArgs.protocolFactory(new TJSONProtocol.Factory()); //TServer server = new TSimpleServer(tArgs); TServer server = new TThreadPoolServer(tArgs); //TServer server = new TNonblockingServer(tArgs); server.serve(); } catch (Exception e) { System.out.println("Server start error!!!"); e.printStackTrace(); } } public static void main(String[] args) { HelloServerDemo server = new HelloServerDemo(); server.startServer(); } }