thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tuan Le Dinh <ldtua...@gmail.com>
Subject How to make a Thrift client for multiple threads?
Date Tue, 07 Jun 2016 09:51:47 GMT
Hello,

I have a working Thrift client in the below snippet.

TTransport transport = new THttpClient(new
Uri("http://localhost:8080/api/"));TProtocol protocol = new
TBinaryProtocol(transport);TMultiplexedProtocol mp = new
TMultiplexedProtocol(protocol, "UserService");UserService.Client
userServiceClient = new
UserService.Client(mp);System.out.println(userServiceClient.getUserById(100));

When running the client within multi-threaded environment

threads[i] = new Thread(new Runnable() {
    @Override
    public void run() {
        System.out.println(userServiceClient.getUserById(someId));
    }}

I got an exception: *out of sequence response*

org.apache.thrift.TApplicationException: getUserById failed: out of
sequence response
at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:76)

I guess the reason is that Thrift generated Client is not thread safe. But
if I want multi-clients to call the same method getUserById() simultaneously,
how can I make it?

I made a copy of this question on Stackoverflow. You can see it here
http://stackoverflow.com/questions/37674466/how-to-make-a-thrift-client-for-multiple-threads
Kind regards,
Tuan Le

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message