Each HTTP connection that your client makes results in overhead. To reduceoverhead, you can batch multiple API calls together into a single HTTP request.
The main classes of interest areBatchRequest andJsonBatchCallback. The following example shows how to usethese classes with service-specific generated libraries:
JsonBatchCallback<Calendar>callback=newJsonBatchCallback<Calendar>(){publicvoidonSuccess(Calendarcalendar,HttpHeadersresponseHeaders){printCalendar(calendar);addedCalendarsUsingBatch.add(calendar);}publicvoidonFailure(GoogleJsonErrore,HttpHeadersresponseHeaders){System.out.println("Error Message: "+e.getMessage());}};...Calendarclient=Calendar.builder(transport,jsonFactory,credential).setApplicationName("BatchExample/1.0").build();BatchRequestbatch=client.batch();Calendarentry1=newCalendar().setSummary("Calendar for Testing 1");client.calendars().insert(entry1).queue(batch,callback);Calendarentry2=newCalendar().setSummary("Calendar for Testing 2");client.calendars().insert(entry2).queue(batch,callback);batch.execute();