An instance of this class represents a single batch of requests.
Sample use:
// client is a AbstractGoogleClient (e.g.// com.google.api.services.books.Books)BatchRequestbatch=client.batch(httpRequestInitializer);batch.queue(volumesList,Volumes.class,GoogleJsonErrorContainer.class,newBatchCallback<Volumes,GoogleJsonErrorContainer>(){publicvoidonSuccess(Volumesvolumes,HttpHeadersresponseHeaders){log("Success");printVolumes(volumes.getItems());}publicvoidonFailure(GoogleJsonErrorContainere,HttpHeadersresponseHeaders){log(e.getError().getMessage());}});batch.queue(volumesList,Volumes.class,GoogleJsonErrorContainer.class,newBatchCallback<Volumes,GoogleJsonErrorContainer>(){publicvoidonSuccess(Volumesvolumes,HttpHeadersresponseHeaders){log("Success");printVolumes(volumes.getItems());}publicvoidonFailure(GoogleJsonErrorContainere,HttpHeadersresponseHeaders){log(e.getError().getMessage());}});batch.execute();
The content of each individual response is stored in memory. There is thus a potential of
encountering an OutOfMemoryError for very large responses.
Redirects are currently not followed in BatchRequest.
Implementation is not thread-safe.
Note: When setting an HttpUnsuccessfulResponseHandler by calling to HttpRequest#setUnsuccessfulResponseHandler, the handler is called for each unsuccessful part. As
a result it's not recommended to use HttpBackOffUnsuccessfulResponseHandler on a batch
request, since the back-off policy is invoked for each unsuccessful part.
Executes all queued HTTP requests in a single call, parses the responses and invokes callbacks.
Calling #execute() executes and clears the queued requests. This means that the
BatchRequest object can be reused to #queue and #execute() requests
again.
[[["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-08-28 UTC."],[],[],null,["# Class BatchRequest (2.8.1)\n\nVersion latestkeyboard_arrow_down\n\n- [2.8.1 (latest)](/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.batch.BatchRequest)\n- [2.8.0](/java/docs/reference/google-api-client/2.8.0/com.google.api.client.googleapis.batch.BatchRequest)\n- [2.7.2](/java/docs/reference/google-api-client/2.7.2/com.google.api.client.googleapis.batch.BatchRequest)\n- [2.6.0](/java/docs/reference/google-api-client/2.6.0/com.google.api.client.googleapis.batch.BatchRequest)\n- [2.5.1](/java/docs/reference/google-api-client/2.5.1/com.google.api.client.googleapis.batch.BatchRequest)\n- [2.4.1](/java/docs/reference/google-api-client/2.4.1/com.google.api.client.googleapis.batch.BatchRequest)\n- [2.1.2](/java/docs/reference/google-api-client/2.1.2/com.google.api.client.googleapis.batch.BatchRequest)\n- [2.0.1](/java/docs/reference/google-api-client/2.0.1/com.google.api.client.googleapis.batch.BatchRequest)\n- [1.35.2](/java/docs/reference/google-api-client/1.35.2/com.google.api.client.googleapis.batch.BatchRequest)\n- [1.34.1](/java/docs/reference/google-api-client/1.34.1/com.google.api.client.googleapis.batch.BatchRequest)\n- [1.33.4](/java/docs/reference/google-api-client/1.33.4/com.google.api.client.googleapis.batch.BatchRequest) \n\n public final class BatchRequest\n\nAn instance of this class represents a single batch of requests.\n\nSample use: \n\n\n // client is a AbstractGoogleClient (e.g.\n // com.google.api.services.books.Books)\n BatchRequest batch = client.batch(httpRequestInitializer);\n batch.queue(volumesList, Volumes.class, GoogleJsonErrorContainer.class,\n new BatchCallback\u003cVolumes, GoogleJsonErrorContainer\u003e() {\n\n public void onSuccess(Volumes volumes, HttpHeaders responseHeaders) {\n log(\"Success\");\n printVolumes(volumes.getItems());\n }\n\n public void onFailure(GoogleJsonErrorContainer e, HttpHeaders responseHeaders) {\n log(e.getError().getMessage());\n }\n });\n batch.queue(volumesList, Volumes.class, GoogleJsonErrorContainer.class,\n new BatchCallback\u003cVolumes, GoogleJsonErrorContainer\u003e() {\n\n public void onSuccess(Volumes volumes, HttpHeaders responseHeaders) {\n log(\"Success\");\n printVolumes(volumes.getItems());\n }\n\n public void onFailure(GoogleJsonErrorContainer e, HttpHeaders responseHeaders) {\n log(e.getError().getMessage());\n }\n });\n batch.execute();\n \nThe content of each individual response is stored in memory. There is thus a potential of\nencountering an OutOfMemoryError for very large responses.\n\nRedirects are currently not followed in [BatchRequest](/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.batch.BatchRequest).\n\nImplementation is not thread-safe.\n\nNote: When setting an HttpUnsuccessfulResponseHandler by calling to HttpRequest#setUnsuccessfulResponseHandler, the handler is called for each unsuccessful part. As\na result it's not recommended to use HttpBackOffUnsuccessfulResponseHandler on a batch\nrequest, since the back-off policy is invoked for each unsuccessful part. \n\nInheritance\n-----------\n\n[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \\\u003e BatchRequest \n\nInherited Members\n-----------------\n\n[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) \n[Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) \n[Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) \n[Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) \n[Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) \n[Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) \n[Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) \n[Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) \n[Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) \n[Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) \n[Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)\n\nConstructors\n------------\n\n### BatchRequest(HttpTransport transport, HttpRequestInitializer httpRequestInitializer) (deprecated)\n\n public BatchRequest(HttpTransport transport, HttpRequestInitializer httpRequestInitializer)\n\n**Deprecated.** *Please use AbstractGoogleClient#batch(HttpRequestInitializer) to instantiate your\nbatch request.*\n\nConstruct the [BatchRequest](/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.batch.BatchRequest).\n\nMethods\n-------\n\n### \\\u003cT,E\\\u003equeue(HttpRequest httpRequest, Class\\\u003cT\\\u003e dataClass, Class\\\u003cE\\\u003e errorClass, BatchCallback\\\u003cT,E\\\u003e callback)\n\n public BatchRequest \u003cT,E\u003equeue(HttpRequest httpRequest, Class\u003cT\u003e dataClass, Class\u003cE\u003e errorClass, BatchCallback\u003cT,E\u003e callback)\n\nQueues the specified HttpRequest for batched execution. Batched requests are executed\nwhen [#execute()](/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.batch.BatchRequest#com_google_api_client_googleapis_batch_BatchRequest_execute__) is called.\n\n### execute()\n\n public void execute()\n\nExecutes all queued HTTP requests in a single call, parses the responses and invokes callbacks.\n\nCalling [#execute()](/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.batch.BatchRequest#com_google_api_client_googleapis_batch_BatchRequest_execute__) executes and clears the queued requests. This means that the\n[BatchRequest](/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.batch.BatchRequest) object can be reused to #queue and [#execute()](/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.batch.BatchRequest#com_google_api_client_googleapis_batch_BatchRequest_execute__) requests\nagain.\n\n### getBatchUrl()\n\n public GenericUrl getBatchUrl()\n\nReturns the URL that will be hit when [#execute()](/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.batch.BatchRequest#com_google_api_client_googleapis_batch_BatchRequest_execute__) is called.\n\n### getSleeper()\n\n public Sleeper getSleeper()\n\nReturns the sleeper.\n\n### setBatchUrl(GenericUrl batchUrl)\n\n public BatchRequest setBatchUrl(GenericUrl batchUrl)\n\nSets the URL that will be hit when [#execute()](/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.batch.BatchRequest#com_google_api_client_googleapis_batch_BatchRequest_execute__) is called. The default value is `\n`\u003chttps://www.googleapis.com/batch\u003e.\n\n### setSleeper(Sleeper sleeper)\n\n public BatchRequest setSleeper(Sleeper sleeper)\n\nSets the sleeper. The default value is [Sleeper#DEFAULT](https://cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.Sleeper.html#com_google_api_client_util_Sleeper_DEFAULT).\n\n### size()\n\n public int size()\n\nReturns the number of queued requests in this batch request."]]