On Tue, Jun 14, 2016 at 5:48 AM, <testark2...@gmail.com> wrote:

> Is it safe to execute a listener using MoreExecutors.directExecutor(), as
> in
>
> ListenableFuture<MyResponse> res = myFutureStub.myMethod(myRequest);
> res.addListener(myCallback, MoreExecutors.directExecutor());
>

We actually support it channel-wide with
ManagedChannelBuilder.directExecutor()
<http://www.grpc.io/grpc-java/javadoc/io/grpc/ManagedChannelBuilder.html#directExecutor-->,
but doing it per-call also works. It is safe as long as you don't block,
which would be necessary for performance but is also important to avoid
accidental deadlocks.

When you are running with directExecutor, you are running on the network
thread which may be shared with between multiple Channels and Servers.

or may I run into problems using this pattern (as I'll be using gRPC's
> default executor's threads)? Most of the time myCallback only sets the
> value of a Spring's DeferredResult and returns, but in a few cases I can't
> address right now it will block the thread for a few milliseconds.
>

If that blocking is a Thread.sleep() you should be fine (although you would
want to reduce the blocking to improve performance/reduce latency). If you
are blocking on other things, you need to make sure that you won't
deadlock. If what you are blocking on is guaranteed to make progress, then
it should be fine.

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to grpc-io@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/CA%2B4M1oPDZU73ea0ETfkQ-uTzTd4mYwbP5%2BDswRGRTBLG%2B-k%2BXw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to