Skip to content

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

Merged
Neenu1995 merged 5 commits into
mainfrom
wrap-thread-only
Jun 18, 2026
Merged

chore(bigquery-jdbc): add the bridge Thread wrap ahead of Executor migration#13482
Neenu1995 merged 5 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.


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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We use sleep for NEW threads because join returns immediately on unstarted threads, which would cause the get() loop to busy-wait and consume 100% CPU until the thread is started. Additionally, checking every 50ms allows the thread calling get() to detect a cancellation request quickly and throw a CancellationException without remaining blocked for a long join timeout.

@Neenu1995 Neenu1995 requested a review from logachev June 17, 2026 15:35
@Neenu1995

Copy link
Copy Markdown
Contributor Author

/gcbrun

@Neenu1995

Copy link
Copy Markdown
Contributor Author

/gcbrun

@Neenu1995 Neenu1995 merged commit 577f6e8 into main Jun 18, 2026
179 of 180 checks passed
@Neenu1995 Neenu1995 deleted the wrap-thread-only branch June 18, 2026 15:22
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