You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2020/04/20 22:19:18 UTC

[GitHub] [commons-lang] kinow commented on a change in pull request #523: Rewrite the finding of matching Locales in LocaleUtils using the Streams API.

kinow commented on a change in pull request #523:
URL: https://github.com/apache/commons-lang/pull/523#discussion_r411729884



##########
File path: src/main/java/org/apache/commons/lang3/LocaleUtils.java
##########
@@ -295,14 +297,13 @@ public static boolean isAvailableLocale(final Locale locale) {
         }
         List<Locale> langs = cLanguagesByCountry.get(countryCode);
         if (langs == null) {
-            langs = new ArrayList<>();
-            final List<Locale> locales = availableLocaleList();
-            for (final Locale locale : locales) {
-                if (countryCode.equals(locale.getCountry()) &&
-                    locale.getVariant().isEmpty()) {
-                    langs.add(locale);
-                }
-            }
+            // Allows Locales to be processed using multiple threads.
+            langs = availableLocaleList().parallelStream()

Review comment:
       From what I remember (sorry, been doing more Python these days), the `parallelStream` could be good or bad. For a low level library, I think it would be bad.
   
   That method starts executors in the background, and I think it's either a fixed number of executors, or based on the number of cores.
   
   But anyway, the point was that if a library uses `parallelStream`, users of the API would have to be aware that there could be small performance peaks due to these extra executors being created. See [this SO question & answers](https://stackoverflow.com/questions/20375176/should-i-always-use-a-parallel-stream-when-possible).
   
   The place where I would use it, would be some small command line utility processing text/files with thousands or millions of lines in a single computer. There I could perhaps use a parallelStream to do some processing.
   
   So for that, for now, I'd be -1 to `parallelStream` here in common (the code looks nicer by the way :)




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