TisonKun 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_r387827116
##########
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:
An alternative is that we always have two final field
```
private final Executor execute;
private final Runnable onClose;
```
and compose the close manner where
```
() -> {} // for passed Executor
() -> ExecutorUtils.gracefulShutdown(5, TimeUnit.SECONDS,
this.internalExecutorService); // for internal service
```
since we initialize `onClose` in constructor we know whether `executor` is a
passed `Executor` or an internal initialized service.
----------------------------------------------------------------
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