2929import java .util .Map ;
3030import java .util .UUID ;
3131import java .util .concurrent .CompletionStage ;
32+ import java .util .concurrent .ScheduledExecutorService ;
3233import java .util .concurrent .ThreadLocalRandom ;
3334import org .apache .beam .sdk .annotations .Internal ;
3435import org .apache .beam .sdk .coders .CannotProvideCoderException ;
4647import org .apache .beam .sdk .io .FileBasedSink .WriteOperation ;
4748import org .apache .beam .sdk .io .FileBasedSink .Writer ;
4849import org .apache .beam .sdk .io .fs .ResourceId ;
50+ import org .apache .beam .sdk .options .ExecutorOptions ;
4951import org .apache .beam .sdk .options .PipelineOptions ;
5052import org .apache .beam .sdk .options .ValueProvider ;
5153import org .apache .beam .sdk .options .ValueProvider .StaticValueProvider ;
@@ -1199,6 +1201,7 @@ public WriteShardsIntoTempFilesFn(Coder<UserT> inputCoder) {
11991201 private transient List <CompletionStage <Void >> closeFutures = new ArrayList <>();
12001202 private transient List <KV <Instant , FileResult <DestinationT >>> deferredOutput =
12011203 new ArrayList <>();
1204+ private transient ScheduledExecutorService executorService ;
12021205
12031206 // Ensure that transient fields are initialized.
12041207 private void readObject (java .io .ObjectInputStream in )
@@ -1208,6 +1211,11 @@ private void readObject(java.io.ObjectInputStream in)
12081211 deferredOutput = new ArrayList <>();
12091212 }
12101213
1214+ @ Setup
1215+ public void setup (PipelineOptions options ) {
1216+ executorService = options .as (ExecutorOptions .class ).getScheduledExecutorService ();
1217+ }
1218+
12111219 @ ProcessElement
12121220 public void processElement (
12131221 ProcessContext c , BoundedWindow window , MultiOutputReceiver outputReceiver )
@@ -1285,7 +1293,8 @@ private void closeWriterInBackground(Writer<DestinationT, OutputT> writer) {
12851293 writer .cleanup ();
12861294 throw e ;
12871295 }
1288- }));
1296+ },
1297+ executorService ));
12891298 }
12901299
12911300 @ FinishBundle
0 commit comments