kl0u opened a new pull request #12719: URL: https://github.com/apache/flink/pull/12719
## What is the purpose of the change A good description of the problem is described in the associated [JIRA](https://issues.apache.org/jira/browse/FLINK-18352). In essence, the singleton nature of the `org.apache.flink.core.execution.DefaultExecutorServiceLoader` class is not enough because the `java.util.ServiceLoader` class is not thread-safe. The same holds for the `DefaultClusterClientServiceLoader`. ## Brief change log The two main changes are split into different commits: 1. We make the `DefaultClusterClientServiceLoader` a singleton so that we have a single instance across the whole codebase. 2. We make both the `DefaultExecutorServiceLoader` and the `DefaultClusterClientServiceLoader` thread-safe by declaring their methods as `synchronized`. We do not expect this to impact performance as this is outside the critical path. ## Verifying this change No new tests were added but it was tested manually with a loop that creates threads and calls `getXXXFactory()`. This cannot be deterministically tested as the failure would happen during the access of the internal loader iterator which we do not have access to. ## Does this pull request potentially affect one of the following parts: - Dependencies (does it add or upgrade a dependency): (yes / **no**) - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (yes / **no**) - The serializers: (yes / **no** / don't know) - The runtime per-record code paths (performance sensitive): (yes / **no** / don't know) - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn/Mesos, ZooKeeper: (yes / **no** / don't know) - The S3 file system connector: (yes / **no** / don't know) ## Documentation - Does this pull request introduce a new feature? (yes / **no**) - If yes, how is the feature documented? (**not applicable** / docs / JavaDocs / not documented) ---------------------------------------------------------------- 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: us...@infra.apache.org