Skip to content

chore(bigquery-jdbc): add the bridge Thread wrap ahead of Executor migration#13482

Open
Neenu1995 wants to merge 3 commits into
mainfrom
wrap-thread-only
Open

chore(bigquery-jdbc): add the bridge Thread wrap ahead of Executor migration#13482
Neenu1995 wants to merge 3 commits into
mainfrom
wrap-thread-only

Conversation

@Neenu1995

Copy link
Copy Markdown
Contributor

No description provided.

@Neenu1995 Neenu1995 requested review from a team as code owners June 15, 2026 17:47

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

Copy link
Copy Markdown
Contributor

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 introduces a temporary compatibility bridge method wrapThread in BigQueryDatabaseMetaData to wrap raw Thread objects into Future instances, along with comprehensive unit tests. A critical issue was identified in the overloaded get(long timeout, TimeUnit unit) method: if the wrapped thread is in the NEW state, calling thread.join() will return immediately, resulting in a tight busy-wait loop that consumes 100% CPU. It is recommended to handle the NEW state by sleeping instead of joining, similar to the no-argument get() implementation.


@Override
public Object get() throws InterruptedException, CancellationException {
if (isCancelled()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Instead of the code duplication, we can call get(timeout, unit) with some absurdly large limit, like 100 days.


long delay = Math.min(remainingMillis, 50);
if (thread.getState() == Thread.State.NEW) {
Thread.sleep(delay);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why the difference sleep vs join?

Also we can just call thread.join(1000);, there is no need to check every 50ms if object was cancelled or not. We have 10-60 second cleanup waiters either way (or worry about < 50 ms remaining time)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants