Thank you David!

Adam.


--- On Sat, 2/27/10, David Reiss <[email protected]> wrote:

> From: David Reiss <[email protected]>
> Subject: Re: thread safe client connections
> To: "[email protected]" <[email protected]>
> Date: Saturday, February 27, 2010, 11:57 PM
> You don't have to close the
> connection immediately.  You can make multiple calls on
> it.
> None of those objects can be shared safely, but you can
> give a client to another thread
> once you are done with it.  Put another way, multiple
> threads can use the same client
> (and protocol and transport), just not at the same time.
> 
> A R wrote:
> > Hello,
> > 
> > I'm writing a multi-threaded non-blocking Thrift
> client application. Each thread will uses its own Thrift
> connection.
> > 
> > I'm not clear what is required for a non-blocking
> thread safe client connection. Does every thread have to
> create the following four values: socket, transport,
> protocol, client? Like this:
> > 
> >     shared_ptr<TTransport>
> socket(new TSocket("localhost", 9090));
> >     shared_ptr<TTransport>
> transport(new TBufferedTransport(socket));
> >     shared_ptr<TProtocol>
> protocol(new TBinaryProtocol(transport));
> > 
> >     MyThriftClient
> client(protocol);
> >     
> >     And then:
> > 
> >     
>    transport->open();
> >         client.ping();
> >     
>    transport->close();
> > 
> > *OR*
> > 
> >     Can one or more values be
> safely shared between threads? For example: socket?
> > 
> >     Also, in the above example the
> thread calls transport->close();
> > 
> >     Can open/close be replaced
> with just an open when the thread is created and leave it
> open() even when the thread is in the pool (sleeping)?
> > 
> > TIA!
> > Adam.
> > 
>

Reply via email to