Reputation: 609
ManagedChannel managedChannel = ManagedChannelBuilder.forTarget(host).usePlaintext().build();
When I should shutdown the managed channel? Sould it be open all time ? Or Should I close this channel after every operations?
Upvotes: 3
Views: 6915
Reputation: 13077
The shutdown can be used if you see the need to close existing connections(ex: streams) and prevent future connections. A possible scenario is an application exit with a clean state (i.e - finalize all network communications and exit).
However, as Fabian highlighted channels are recommended to be reused where possible. This is further confirmed from the performance best practices guide
Always re-use stubs and channels when possible.
Upvotes: 0
Reputation: 3950
It's intended to be kept open and reused across your application. See for instance this thread on github, in which one of the contributors states:
Channels are expensive to create, and the general recommendation is to use one per application, shared among the service stubs.
Upvotes: 7