File tree Expand file tree Collapse file tree
google-cloud-clients/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1 Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -313,20 +313,22 @@ public void run() {
313313 */
314314 public void publishAllOutstanding () {
315315 messagesBatchLock .lock ();
316+ List <MessagesBatch > toSend ;
316317 try {
317- for (MessagesBatch batch : messagesBatches .values ()) {
318- if (!batch .isEmpty ()) {
319- // TODO(kimkyung-goog): Do not release `messagesBatchLock` when publishing a batch. If
320- // it's released, the order of publishing cannot be guaranteed if `publish()` is called
321- // while this function is running. This locking mechanism needs to be improved if it
322- // causes any performance degradation.
323- publishOutstandingBatch (batch .popOutstandingBatch ());
324- }
325- }
318+ toSend = new ArrayList <>(messagesBatches .values ());
326319 messagesBatches .clear ();
327320 } finally {
328321 messagesBatchLock .unlock ();
329322 }
323+ for (MessagesBatch batch : toSend ) {
324+ if (!batch .isEmpty ()) {
325+ // TODO(kimkyung-goog): Do not release `messagesBatchLock` when publishing a batch. If
326+ // it's released, the order of publishing cannot be guaranteed if `publish()` is called
327+ // while this function is running. This locking mechanism needs to be improved if it
328+ // causes any performance degradation.
329+ publishOutstandingBatch (batch .popOutstandingBatch ());
330+ }
331+ }
330332 }
331333
332334 private ApiFuture <PublishResponse > publishCall (OutstandingBatch outstandingBatch ) {
You can’t perform that action at this time.
0 commit comments