Helper class to configure timeouts for specific Spanner RPCs. The SpannerCallContextTimeoutConfigurator must be set as a value on the Context using the SpannerOptions#CALL_CONTEXT_CONFIGURATOR_KEY key.
Example usage:
// Create a context with a ExecuteQuery timeout of 10 seconds.
Context context =
Context.current()
.withValue(
SpannerOptions.CALL_CONTEXT_CONFIGURATOR_KEY,
SpannerCallContextTimeoutConfigurator.create()
.withExecuteQueryTimeout(Duration.ofSeconds(10L)));
context.run(
() -> {
try (ResultSet rs =
client
.singleUse()
.executeQuery(
Statement.of(
"SELECT SingerId, FirstName, LastName FROM Singers ORDER BY LastName"))) {
while (rs.next()) {
System.out.printf("%d %s %s%n", rs.getLong(0), rs.getString(1), rs.getString(2));
}
} catch (SpannerException e) {
if (e.getErrorCode() == ErrorCode.DEADLINE_EXCEEDED) {
// Handle timeout.
}
}
}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-06-05 UTC."],[],[]]