tillrohrmann commented on a change in pull request #10971: [FLINK-15791][k8s] 
Use explicit I/O Executor for asynchronous operations in Fabric8FlinkKubeClient
URL: https://github.com/apache/flink/pull/10971#discussion_r387819556
 
 

 ##########
 File path: 
flink-kubernetes/src/main/java/org/apache/flink/kubernetes/kubeclient/Fabric8FlinkKubeClient.java
 ##########
 @@ -355,4 +372,33 @@ private int getServiceNodePort(Service service, 
ConfigOption<Integer> configPort
                }
                return port;
        }
+
+       /**
+        * The help class to get the executor to run asynchronous operations 
on. It could create a dedicated thread pool or
+        * reuse an existing one.
+        */
+       private static class ExecutorWrapper {
+
+               private final ExecutorService internalExecutorService;
+               private Executor executor = null;
+
+               ExecutorWrapper(Configuration flinkConfig) {
+                       internalExecutorService = Executors.newFixedThreadPool(
+                               
flinkConfig.getInteger(KubernetesConfigOptions.CLIENT_ASYNC_THREAD_POOL_SIZE),
+                               new 
ExecutorThreadFactory("FlinkKubeClient-IO"));
+               }
+
+               ExecutorWrapper(Configuration flinkConfig, Executor executor) {
+                       this(flinkConfig);
+                       this.executor = executor;
+               }
+
+               Executor getExecutor() {
+                       return executor == null ? this.internalExecutorService 
: executor;
+               }
+
+               public void close() {
+                       ExecutorUtils.gracefulShutdown(5, TimeUnit.SECONDS, 
this.internalExecutorService);
+               }
+       }
 
 Review comment:
   I think your idea here goes in the right direction. But instead of mixing 
the cases (providing an explicit `Executor` vs. creating your own executor 
service), I would suggest to split them and have two implementations of 
`ExecutorWrapper`. At least we should change the implementation that we don't 
always create a `internalExecutorService`. One could do this by only allowing 
two factory methods for the `ExecutorWrapper`, one for the `Executor` case and 
the other for the internal executor. Then one of internal fields of 
`ExecutorWrapper` would be `null` and the other would be not `null`.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to