8000 Add connection pooling comment + region tag (#2776) · ileinone/java-docs-samples@ff3e436 · GitHub
[go: up one dir, main page]

Skip to content

Commit ff3e436

Browse files
author
Ace Nassri
authored
Add connection pooling comment + region tag (GoogleCloudPlatform#2776)
The Apache `httpclient` offers a more configurable implementation, but `java.net.httpClient` seems to [support connection pooling as well.](https://stackoverflow.com/questions/53617574/how-to-keep-connection-alive-in-java-11-http-client) I suspect this simpler, automatic implementation is fine for our docs - but I'll let @kurtisvg and @labtopia be the judges of that.
1 parent 208438a commit ff3e436

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

functions/http/send-http-request/src/main/java/functions/SendHttpRequest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package functions;
1818

1919
// [START functions_concepts_requests]
20+
// [START functions_tips_connection_pooling]
2021

2122
import com.google.cloud.functions.HttpFunction;
2223
import com.google.cloud.functions.HttpRequest;
@@ -31,6 +32,7 @@
3132
public class SendHttpRequest implements HttpFunction {
3233

3334
// Create a client with some reasonable defaults. This client can be reused for multiple requests.
35+
// (java.net.httpClient also pools connections automatically by default.)
3436
private static HttpClient client =
3537
HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(10)).build();
3638

@@ -52,3 +54,4 @@ public void service(HttpRequest request, HttpResponse response)
5254
}
5355
}
5456
// [END functions_concepts_requests]
57+
// [END functions_tips_connection_pooling]

0 commit comments

Comments
 (0)
0