wypoon 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_r373692071
########## 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: Implemented this and updated the PR description. ---------------------------------------------------------------- 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