You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@livy.apache.org by GitBox <gi...@apache.org> on 2020/02/04 21:55:34 UTC

[GitHub] [incubator-livy] wypoon commented on a change in pull request #275: [LIVY-745] Ensure that a single RSCClientFactory gets loaded.

wypoon commented on a change in pull request #275: [LIVY-745] Ensure that a single RSCClientFactory gets loaded.
URL: https://github.com/apache/incubator-livy/pull/275#discussion_r374945260
 
 

 ##########
 File path: api/src/main/java/org/apache/livy/LivyClientBuilder.java
 ##########
 @@ -118,27 +121,29 @@ public LivyClient build() {
     }
 
     LivyClient client = null;
-    ServiceLoader<LivyClientFactory> loader = ServiceLoader.load(LivyClientFactory.class,
-      classLoader());
-    if (!loader.iterator().hasNext()) {
-      throw new IllegalStateException("No LivyClientFactory implementation was found.");
-    }
-
-    Exception error = null;
-    for (LivyClientFactory factory : loader) {
-      try {
-        client = factory.createClient(uri, config);
-      } catch (Exception e) {
-        if (!(e instanceof RuntimeException)) {
-          e = new RuntimeException(e);
+    boolean loaded = false;
+    // ServiceLoader instances are not safe for use by multiple concurrent threads.
+    // Ensure that the ServiceLoader's iterator is called by only one thread at a time.
+    synchronized (CLIENT_FACTORY_LOADER) {
 
 Review comment:
   What I decided to do is to load the service providers into a static List that has a thread-safe iterator. Then LivyClientBuilder#build can iterate through the client factories in this List.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services