diff --git a/samples/snippets/src/main/java/com/example/spanner/StatementTimeoutExample.java b/samples/snippets/src/main/java/com/example/spanner/StatementTimeoutExample.java index 2a82467754..3e75b2fed6 100644 --- a/samples/snippets/src/main/java/com/example/spanner/StatementTimeoutExample.java +++ b/samples/snippets/src/main/java/com/example/spanner/StatementTimeoutExample.java @@ -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"; @@ -52,6 +54,10 @@ public ApiCallContext configure(ApiCallContext context, ReqT reque MethodDescriptor 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)); } @@ -73,4 +79,5 @@ public ApiCallContext configure(ApiCallContext context, ReqT reque }) ); } + // [END spanner_set_statement_timeout] }