GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: provide API to share the same background executor for channel po… by mutianf · Pull Request #4030 · googleapis/sdk-platform-java

This repository was archived by the owner on Oct 29, 2026. It is now read-only.

Conversation

@mutianf

@mutianf mutianf commented Dec 30, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

…ol resizing and refresh

Before this change ChannelPool creates a new SingleThreadScheduledExecutor every time getTransportChannel is called. We can reuse the same background executor from the clientSettings and can reduce the number of threads when the user creates many instances of the client.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mutianf
fix: provide API to share the same background executor for channel po…
60d2c1a
…ol resizing and refresh
@product-auto-label product-auto-label Bot added the size: s Pull request size is small. label Dec 30, 2025
@gemini-code-assist

gemini-code-assist Bot commented Dec 30, 2025

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @mutianf, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant optimization by allowing the ChannelPool to reuse a shared ScheduledExecutorService for its background tasks, such as channel resizing and refresh. Previously, each ChannelPool instance would create its own single-threaded executor, leading to an unnecessary proliferation of threads when many client instances were initialized. By providing an API to share a common background executor, this change aims to reduce resource consumption and enhance the overall performance and scalability of applications using GAX gRPC clients.

Highlights

  • Executor Sharing: The ChannelPool now accepts a ScheduledExecutorService from the InstantiatingGrpcChannelProvider instead of creating its own, allowing for a shared background executor.
  • Resource Optimization: This change reduces the number of threads created when multiple client instances are used, preventing resource exhaustion and improving efficiency.
  • API Enhancement: A new setBackgroundExecutor method has been added to InstantiatingGrpcChannelProvider.Builder to allow users to configure the shared background executor.
  • Code Clarity: The internal executor field in ChannelPool has been renamed to backgroundExecutor for better readability and consistency.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gemini-code-assist[bot]
gemini-code-assist Bot reviewed Dec 30, 2025
View reviewed changes

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request aims to reduce thread creation by allowing a shared ScheduledExecutorService to be used for ChannelPool maintenance tasks. While the goal is good, the current implementation introduces critical lifecycle management issues. Specifically, the ChannelPool now shuts down the provided executor, which is incorrect for a shared resource. Additionally, the InstantiatingGrpcChannelProvider creates a default executor that can be leaked if not used. My review includes comments detailing these issues and suggesting a safer approach to manage the executor's lifecycle.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPool.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@mutianf
fix tests
7c1892a
@product-auto-label product-auto-label Bot added size: m Pull request size is medium. and removed size: s Pull request size is small. labels Dec 30, 2025
@mutianf
update executor lifecycle management
38aaa5a
igorbernstein2
igorbernstein2 reviewed Jan 5, 2026
View reviewed changes
Comment thread gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPool.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

igorbernstein2
igorbernstein2 reviewed Jan 5, 2026
View reviewed changes
Comment thread gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPool.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

igorbernstein2
igorbernstein2 reviewed Jan 5, 2026
View reviewed changes
Comment thread gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPool.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

igorbernstein2
igorbernstein2 reviewed Jan 5, 2026
View reviewed changes
Comment thread gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPool.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

igorbernstein2
igorbernstein2 reviewed Jan 5, 2026
View reviewed changes
Comment thread gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPool.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

igorbernstein2
igorbernstein2 reviewed Jan 5, 2026
View reviewed changes
Comment thread gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPool.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

igorbernstein2
igorbernstein2 reviewed Jan 5, 2026
View reviewed changes
Comment thread gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@blakeli0

blakeli0 commented Jan 5, 2026

Copy link
Copy Markdown
Contributor

I think this is generally a good change. However, what are the use cases that customers have to create many instances of clients?

In general we recommend to use only one client. Creating many clients have other implications, for example, the effort of loading credentials and creating channels would be duplicated. Customers can always pass their own CredentialProvider and ChannelProvider but it may easily misconfigured.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mutianf added 3 commits January 5, 2026 20:49
@mutianf
address comments
98cad91
@mutianf
update order of canceling future
58dc3ee
@mutianf
reformat
b27e890
@mutianf

mutianf commented Jan 6, 2026

Copy link
Copy Markdown
Contributor Author

@blakeli0 They have an application that targets multiple bigtable instances with different retry settings.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

igorbernstein2
igorbernstein2 reviewed Jan 6, 2026
View reviewed changes
Comment thread gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPool.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

igorbernstein2
igorbernstein2 reviewed Jan 6, 2026
View reviewed changes
Comment thread gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPool.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

igorbernstein2
igorbernstein2 reviewed Jan 6, 2026
View reviewed changes
Comment thread gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/ChannelPool.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@mutianf
address comments
0538adf
@blakeli0

blakeli0 commented Jan 6, 2026

Copy link
Copy Markdown
Contributor

@blakeli0 They have an application that targets multiple bigtable instances with different retry settings.

I see, would having a request level retry setting help in this case?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

igorbernstein2
igorbernstein2 reviewed Jan 6, 2026
View reviewed changes
Comment thread gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

mutianf and others added 2 commits January 6, 2026 12:46
@mutianf
add clirr
77e5b15
@blakeli0
Merge branch 'main' into thread
eaec216
@blakeli0

blakeli0 commented Jan 6, 2026

Copy link
Copy Markdown
Contributor

/gcbrun

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

igorbernstein2
igorbernstein2 approved these changes Jan 6, 2026
View reviewed changes
blakeli0
blakeli0 reviewed Jan 6, 2026
View reviewed changes
Comment thread gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java
}

@Override
public TransportChannelProvider withBackgroundExecutor(ScheduledExecutorService executor) {

@blakeli0 blakeli0 Jan 6, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we plan to use it? Do we expect customers to create an InstantiatingGrpcChannelProvider with their own executor?
I see that the same executor is being passed to both executor and backgroundExecutor in ClientContext, if that's the expected use case, we don't have to create new setter methods in TransportChannel.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@mutianf mutianf Jan 7, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ChannelProvider can have 2 executors: background executor and executor. Executor is used for handling rpc callbakcs. Background executor is used for all other background tasks. In the GrpcChannelProvider case, it doesn't need an executor because Grpc ManagedChannel provides a default executor that's optimized for performance. And the background executor is used for managing channels in the channel pool. Normally we don't want to use the same background executor for callbacks and background tasks because it impacts the performances. The settings you see in ClientContext is a bit confusing and it's from an old fix where we deprecated overriding the default grpc executor on the managed channel: 95c4c7b#diff-4e2f6e463b9b7d89de68e3f1a87765080045880c8dad018750f269e311f2471f. I don't think we actually go into the if statement by default

    if (transportChannelProvider.needsExecutor() && settings.getExecutorProvider() != null) {
      transportChannelProvider = transportChannelProvider.withExecutor(backgroundExecutor);
    }

because settings.getExecutorProvider() is null. Maybe it'll be easier to understand if the code is transportChannelProvider.withExecutor(settings.getExecutorProvider().getExecutor());? I made the change.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@blakeli0 blakeli0 Jan 7, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, that's much easier to understand. Thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mutianf
make code easier to understand
dbb5402
@blakeli0

blakeli0 commented Jan 7, 2026

Copy link
Copy Markdown
Contributor

/gcbrun

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

blakeli0
blakeli0 approved these changes Jan 7, 2026
View reviewed changes
@blakeli0
blakeli0 merged commit 178182c into googleapis:main Jan 8, 2026
This was referenced Jan 5, 2026
chore(main): release 2.65.0 #4020
Closed
chore(main): release 2.65.0 #4058
Merged
diegomarquezp pushed a commit that referenced this pull request Jan 13, 2026
@release-please
chore(main): release 2.65.0 (#4058)
972f87a
🤖 I have created a release *beep* *boop*
---


<details><summary>2.65.0</summary>

##
[2.65.0](v2.64.2...v2.65.0)
(2026-01-12)


### Features

* add org.json:json to third-party-dependencies pom
([#4047](#4047))
([ffa432e](ffa432e)),
closes
[#4046](#4046)
* remove dependency management of graal-sdk
([#4033](#4033))
([ad05c34](ad05c34))


### Bug Fixes

* add api_version breadcrumb to client docs
([#4018](#4018))
([a2b2179](a2b2179))
* Create a single S2AChannelCredentials per application
([#3989](#3989))
([3758b43](3758b43))
* provide API to share the same background executor for channel po…
([#4030](#4030))
([178182c](178182c))


### Dependencies

* update dependencies.txt for grpc-gcp to 1.9.0
([#4025](#4025))
([b68791d](b68791d))
* update google api dependencies
([#3917](#3917))
([480cf13](480cf13))
* update google.http-client.version to 2.0.3
([#4054](#4054))
([b9a8c89](b9a8c89))


### Documentation

* Fix retry guide link in javadocs
([#4029](#4029))
([b43f77c](b43f77c))
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
diegomarquezp pushed a commit that referenced this pull request Jan 21, 2026
@release-please @diegomarquezp
chore(main): release 2.65.0 (#4058)
5218acb
🤖 I have created a release *beep* *boop*
---


<details><summary>2.65.0</summary>

##
[2.65.0](v2.64.2...v2.65.0)
(2026-01-12)


### Features

* add org.json:json to third-party-dependencies pom
([#4047](#4047))
([ffa432e](ffa432e)),
closes
[#4046](#4046)
* remove dependency management of graal-sdk
([#4033](#4033))
([ad05c34](ad05c34))


### Bug Fixes

* add api_version breadcrumb to client docs
([#4018](#4018))
([a2b2179](a2b2179))
* Create a single S2AChannelCredentials per application
([#3989](#3989))
([3758b43](3758b43))
* provide API to share the same background executor for channel po…
([#4030](#4030))
([178182c](178182c))


### Dependencies

* update dependencies.txt for grpc-gcp to 1.9.0
([#4025](#4025))
([b68791d](b68791d))
* update google api dependencies
([#3917](#3917))
([480cf13](480cf13))
* update google.http-client.version to 2.0.3
([#4054](#4054))
([b9a8c89](b9a8c89))


### Documentation

* Fix retry guide link in javadocs
([#4029](#4029))
([b43f77c](b43f77c))
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
lqiu96 pushed a commit that referenced this pull request Feb 12, 2026
@mutianf @blakeli0 @lqiu96
fix: provide API to share the same background executor for channel po… (
c10af5a
#4030)

…ol resizing and refresh

Before this change ChannelPool creates a new
SingleThreadScheduledExecutor every time getTransportChannel is called.
We can reuse the same background executor from the clientSettings and
can reduce the number of threads when the user creates many instances of
the client.

---------

Co-authored-by: Blake Li <[email protected]>
lqiu96 pushed a commit that referenced this pull request Feb 12, 2026
@release-please @lqiu96
chore(main): release 2.65.0 (#4058)
b4704f8
🤖 I have created a release *beep* *boop*
---


<details><summary>2.65.0</summary>

##
[2.65.0](v2.64.2...v2.65.0)
(2026-01-12)


### Features

* add org.json:json to third-party-dependencies pom
([#4047](#4047))
([ffa432e](ffa432e)),
closes
[#4046](#4046)
* remove dependency management of graal-sdk
([#4033](#4033))
([ad05c34](ad05c34))


### Bug Fixes

* add api_version breadcrumb to client docs
([#4018](#4018))
([a2b2179](a2b2179))
* Create a single S2AChannelCredentials per application
([#3989](#3989))
([3758b43](3758b43))
* provide API to share the same background executor for channel po…
([#4030](#4030))
([178182c](178182c))


### Dependencies

* update dependencies.txt for grpc-gcp to 1.9.0
([#4025](#4025))
([b68791d](b68791d))
* update google api dependencies
([#3917](#3917))
([480cf13](480cf13))
* update google.http-client.version to 2.0.3
([#4054](#4054))
([b9a8c89](b9a8c89))


### Documentation

* Fix retry guide link in javadocs
([#4029](#4029))
([b43f77c](b43f77c))
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
chingor13 pushed a commit to googleapis/google-cloud-java that referenced this pull request Mar 24, 2026
@release-please
chore(main): release 2.65.0 (#4058)
0d09c8a
🤖 I have created a release *beep* *boop*
---


<details><summary>2.65.0</summary>

##
[2.65.0](googleapis/sdk-platform-java@v2.64.2...v2.65.0)
(2026-01-12)


### Features

* add org.json:json to third-party-dependencies pom
([#4047](googleapis/sdk-platform-java#4047))
([5898abd](googleapis/sdk-platform-java@5898abd)),
closes
[#4046](googleapis/sdk-platform-java#4046)
* remove dependency management of graal-sdk
([#4033](googleapis/sdk-platform-java#4033))
([09ec2a3](googleapis/sdk-platform-java@09ec2a3))


### Bug Fixes

* add api_version breadcrumb to client docs
([#4018](googleapis/sdk-platform-java#4018))
([0573232](googleapis/sdk-platform-java@0573232))
* Create a single S2AChannelCredentials per application
([#3989](googleapis/sdk-platform-java#3989))
([6a24164](googleapis/sdk-platform-java@6a24164))
* provide API to share the same background executor for channel po…
([#4030](googleapis/sdk-platform-java#4030))
([051f76a](googleapis/sdk-platform-java@051f76a))


### Dependencies

* update dependencies.txt for grpc-gcp to 1.9.0
([#4025](googleapis/sdk-platform-java#4025))
([2376f6c](googleapis/sdk-platform-java@2376f6c))
* update google api dependencies
([#3917](googleapis/sdk-platform-java#3917))
([bf94a0a](googleapis/sdk-platform-java@bf94a0a))
* update google.http-client.version to 2.0.3
([#4054](googleapis/sdk-platform-java#4054))
([343a8ef](googleapis/sdk-platform-java@343a8ef))


### Documentation

* Fix retry guide link in javadocs
([#4029](googleapis/sdk-platform-java#4029))
([4bb3ccc](googleapis/sdk-platform-java@4bb3ccc))
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

3 more reviewers
@gemini-code-assist gemini-code-assist[bot] gemini-code-assist[bot] left review comments
@blakeli0 blakeli0 blakeli0 approved these changes
@igorbernstein2 igorbernstein2 igorbernstein2 approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

size: m Pull request size is medium.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@mutianf @blakeli0 @igorbernstein2
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.