Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

class StatementTimeoutExample {

// [START spanner_set_statement_timeout]

static void executeSqlWithTimeout() {
// TODO(developer): Replace these variables before running the sample.
String projectId = "my-project";
Expand All @@ -52,6 +54,10 @@ public <ReqT, RespT> ApiCallContext configure(ApiCallContext context, ReqT reque
MethodDescriptor<ReqT, RespT> method) {
// DML uses the ExecuteSql RPC.
if (method == SpannerGrpc.getExecuteSqlMethod()) {
// NOTE: You can use a GrpcCallContext to set a custom timeout for a single RPC
// invocation. This timeout can however ONLY BE SHORTER than the default timeout
// for the RPC. If you set a timeout that is longer than the default timeout, then
// the default timeout will be used.
return GrpcCallContext.createDefault()
.withCallOptions(CallOptions.DEFAULT.withDeadlineAfter(60L, TimeUnit.SECONDS));
}
Expand All @@ -73,4 +79,5 @@ public <ReqT, RespT> ApiCallContext configure(ApiCallContext context, ReqT reque
})
);
}
// [END spanner_set_statement_timeout]
}