Thread safety in Grpc java clients

2,005 views
Skip to first unread message

ccl...@dieselpoint.com

unread,
Aug 30, 2016, 5:36:15 PM8/30/16
to grpc.io
I'm confused on how threads work in Grpc. If I create a stub, either blocking or non blocking, can I share it across threads? Will a call to one of the stub's methods be handled in a thread-safe way?

Is it common to create a new stub for each call? Or can I use one that persists for a long time?

What about channels on the client side? Thread safe?

Can I share a channel across stubs? Or should each stub get its own channel?

Louis Ryan

unread,
Aug 30, 2016, 5:41:27 PM8/30/16
to ccl...@dieselpoint.com, grpc.io
On Tue, Aug 30, 2016 at 2:36 PM, <ccl...@dieselpoint.com> wrote:
I'm confused on how threads work in Grpc. If I create a stub, either blocking or non blocking, can I share it across threads?
Yes 
Will a call to one of the stub's methods be handled in a thread-safe way?
Yes 

Is it common to create a new stub for each call?

Yes but only if you need to change the behavior of the stub. E.g to change deadlines for calls.
 
Or can I use one that persists for a long time?

Yes 

What about channels on the client side? Thread safe?

Yes 

Can I share a channel across stubs? Or should each stub get its own channel?

Share a channel with lots of stubs for connection re-use. 
 

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+unsubscribe@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/d27c5f45-65f5-4da6-9c04-56118279ceab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages