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

 ##########
 File path: api/src/main/java/org/apache/livy/LivyClientBuilder.java
 ##########
 @@ -118,24 +121,21 @@ 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);
+    // 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 (LivyClientBuilder.class) {
 
 Review comment:
   shall we sync on `CLIENT_FACTORY_LOADER` maybe?

----------------------------------------------------------------
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


With regards,
Apache Git Services

Reply via email to