Is there ever a reason not to use Java 8's parallelSort?Difference between Arrays.sort() and Arrays.parallelSort()Is Java “pass-by-reference” or “pass-by-value”?How do I efficiently iterate over each entry in a Java Map?Does a finally block always get executed in Java?What is the difference between public, protected, package-private and private in Java?How do I read / convert an InputStream into a String in Java?When to use LinkedList over ArrayList in Java?How do I generate random integers within a specific range in Java?How do I determine whether an array contains a particular value in Java?How do I convert a String to an int in Java?Creating a memory leak with Java

Isn't "Dave's protocol" good if only the database, and not the code, is leaked?

How to create a 2D table with varying step?

Is my background sufficient to start Quantum Computing

Is it possible to spoof an IP address to an exact number?

Can Monks cast spells?

What is the difference between a historical drama and a period drama?

What is a "tittering order"?

Blood-based alcohol for vampires?

Construction of the word подтвержда́ть

How is /a/ pronounced before n/m in French?

"Best practices" for formulating MIPs

Performance of loop vs expansion

What could a Medieval society do with excess animal blood?

Where is read command?

Show that there are infinitely more problems than we will ever be able to compute

Is there any connection between "Whispers of the heart" and "The cat returns"?

Phrasing "it says" or "it reads"

Is there ever a reason not to use Java 8's parallelSort?

Is it possible that Curiosity measured its own methane or failed doing the spectrometry?

Olive oil in Japanese cooking

What do you call the angle of the direction of an airplane?

Why did my leaking pool light trip the circuit breaker, but not the GFCI?

Auto replacement of characters

Why did moving the mouse cursor cause Windows 95 to run more quickly?



Is there ever a reason not to use Java 8's parallelSort?


Difference between Arrays.sort() and Arrays.parallelSort()Is Java “pass-by-reference” or “pass-by-value”?How do I efficiently iterate over each entry in a Java Map?Does a finally block always get executed in Java?What is the difference between public, protected, package-private and private in Java?How do I read / convert an InputStream into a String in Java?When to use LinkedList over ArrayList in Java?How do I generate random integers within a specific range in Java?How do I determine whether an array contains a particular value in Java?How do I convert a String to an int in Java?Creating a memory leak with Java






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








10















I was reading this question about the differences between Java's Arrays.sort and Arrays.parallelSort, which is a few years old by now. What surprised me is that there was only one question that mentioned any downside to using parallelSort; namely that the speedup decreases if you're using a lot of your CPU.



Assuming you're not in some sort of specialized, single-threaded environment, should one always choose parallelSort? Is there ever a reason not to? Note that one of the answers to the question above mentions that if there are fewer than 4096 elements, parallelSort simply calls sort anyway.










share|improve this question
























  • It might be a problem when running in a Java EE container.

    – JF Meier
    8 hours ago






  • 1





    @JFMeier no, Arrays.parallelSort explicitly checks if the common pool has only one thread and thus won't perform worse (compared to the non-parallel sort) with only 1 thread in the common pool, see here for example. But yes, the common pool has very little / 1 thread(s) in a servlet context, which may be a pitfall

    – roookeee
    8 hours ago


















10















I was reading this question about the differences between Java's Arrays.sort and Arrays.parallelSort, which is a few years old by now. What surprised me is that there was only one question that mentioned any downside to using parallelSort; namely that the speedup decreases if you're using a lot of your CPU.



Assuming you're not in some sort of specialized, single-threaded environment, should one always choose parallelSort? Is there ever a reason not to? Note that one of the answers to the question above mentions that if there are fewer than 4096 elements, parallelSort simply calls sort anyway.










share|improve this question
























  • It might be a problem when running in a Java EE container.

    – JF Meier
    8 hours ago






  • 1





    @JFMeier no, Arrays.parallelSort explicitly checks if the common pool has only one thread and thus won't perform worse (compared to the non-parallel sort) with only 1 thread in the common pool, see here for example. But yes, the common pool has very little / 1 thread(s) in a servlet context, which may be a pitfall

    – roookeee
    8 hours ago














10












10








10


2






I was reading this question about the differences between Java's Arrays.sort and Arrays.parallelSort, which is a few years old by now. What surprised me is that there was only one question that mentioned any downside to using parallelSort; namely that the speedup decreases if you're using a lot of your CPU.



Assuming you're not in some sort of specialized, single-threaded environment, should one always choose parallelSort? Is there ever a reason not to? Note that one of the answers to the question above mentions that if there are fewer than 4096 elements, parallelSort simply calls sort anyway.










share|improve this question
















I was reading this question about the differences between Java's Arrays.sort and Arrays.parallelSort, which is a few years old by now. What surprised me is that there was only one question that mentioned any downside to using parallelSort; namely that the speedup decreases if you're using a lot of your CPU.



Assuming you're not in some sort of specialized, single-threaded environment, should one always choose parallelSort? Is there ever a reason not to? Note that one of the answers to the question above mentions that if there are fewer than 4096 elements, parallelSort simply calls sort anyway.







java sorting parallel-processing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 8 hours ago









John Kugelman

256k56 gold badges416 silver badges467 bronze badges




256k56 gold badges416 silver badges467 bronze badges










asked 8 hours ago









Calvin GodfreyCalvin Godfrey

9932 silver badges15 bronze badges




9932 silver badges15 bronze badges












  • It might be a problem when running in a Java EE container.

    – JF Meier
    8 hours ago






  • 1





    @JFMeier no, Arrays.parallelSort explicitly checks if the common pool has only one thread and thus won't perform worse (compared to the non-parallel sort) with only 1 thread in the common pool, see here for example. But yes, the common pool has very little / 1 thread(s) in a servlet context, which may be a pitfall

    – roookeee
    8 hours ago


















  • It might be a problem when running in a Java EE container.

    – JF Meier
    8 hours ago






  • 1





    @JFMeier no, Arrays.parallelSort explicitly checks if the common pool has only one thread and thus won't perform worse (compared to the non-parallel sort) with only 1 thread in the common pool, see here for example. But yes, the common pool has very little / 1 thread(s) in a servlet context, which may be a pitfall

    – roookeee
    8 hours ago

















It might be a problem when running in a Java EE container.

– JF Meier
8 hours ago





It might be a problem when running in a Java EE container.

– JF Meier
8 hours ago




1




1





@JFMeier no, Arrays.parallelSort explicitly checks if the common pool has only one thread and thus won't perform worse (compared to the non-parallel sort) with only 1 thread in the common pool, see here for example. But yes, the common pool has very little / 1 thread(s) in a servlet context, which may be a pitfall

– roookeee
8 hours ago






@JFMeier no, Arrays.parallelSort explicitly checks if the common pool has only one thread and thus won't perform worse (compared to the non-parallel sort) with only 1 thread in the common pool, see here for example. But yes, the common pool has very little / 1 thread(s) in a servlet context, which may be a pitfall

– roookeee
8 hours ago













2 Answers
2






active

oldest

votes


















9














There are some downsides to using Arrays.parallelSort



  • it uses the ForkJoinPool.commonPool() and will fight with other functions that use it by default (e.g. parallel() on a stream)

  • the thread-pool Arrays.parallelSort uses is not configurable (only on a global level by increasing the common-pools thread amount)

  • it performs worse on small data sets (more often than not arrays contain little elements, the JDK even acknowledges that e.g. most ArrayList stay empty for their whole lifetime which saves quite a bit of memory and CPU time for not instantiating arrays that will never be filled)

And another anecdotal scenario: say if you implement some card game that needs sorting. Its embarassingly easy to parallelize multiple game executions next to each other instead of parallelizing the sorting mechanism of one run which may only take a fraction of the whole game loop. You lost an easy way to parallelize now.



But yes, if you happen to have large arrays and sorting is a substantial part of your applications runtime use Arrays.parallelSort.



EDIT:
And even if Arrays.parallelSort switches to a normal sort if the given array has less than 4096 elements: it's all about showing intention - you want a parallel sort if possible which holds a different meaning than just calling sort. And to be nitpicky: it does indeed perform worse on small arrays as it has to do the additional check if the array is containing less than 4096 elements and some other checks about the common pools thread count (whichs overhead is of course negligible) :).






share|improve this answer
































    2














    No, I would say no for small enough arrays. The overhead of setting up the threads won't result in an observable speed up.



    The key is "small enough". It won't be the same answer for all problems.



    Dogma should never be applied, except in the case of this dogma rule. Just like the only thing we should never tolerate is intolerance. There's a Popper paradox in there somewhere.






    share|improve this answer

























      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f56841334%2fis-there-ever-a-reason-not-to-use-java-8s-parallelsort%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      9














      There are some downsides to using Arrays.parallelSort



      • it uses the ForkJoinPool.commonPool() and will fight with other functions that use it by default (e.g. parallel() on a stream)

      • the thread-pool Arrays.parallelSort uses is not configurable (only on a global level by increasing the common-pools thread amount)

      • it performs worse on small data sets (more often than not arrays contain little elements, the JDK even acknowledges that e.g. most ArrayList stay empty for their whole lifetime which saves quite a bit of memory and CPU time for not instantiating arrays that will never be filled)

      And another anecdotal scenario: say if you implement some card game that needs sorting. Its embarassingly easy to parallelize multiple game executions next to each other instead of parallelizing the sorting mechanism of one run which may only take a fraction of the whole game loop. You lost an easy way to parallelize now.



      But yes, if you happen to have large arrays and sorting is a substantial part of your applications runtime use Arrays.parallelSort.



      EDIT:
      And even if Arrays.parallelSort switches to a normal sort if the given array has less than 4096 elements: it's all about showing intention - you want a parallel sort if possible which holds a different meaning than just calling sort. And to be nitpicky: it does indeed perform worse on small arrays as it has to do the additional check if the array is containing less than 4096 elements and some other checks about the common pools thread count (whichs overhead is of course negligible) :).






      share|improve this answer





























        9














        There are some downsides to using Arrays.parallelSort



        • it uses the ForkJoinPool.commonPool() and will fight with other functions that use it by default (e.g. parallel() on a stream)

        • the thread-pool Arrays.parallelSort uses is not configurable (only on a global level by increasing the common-pools thread amount)

        • it performs worse on small data sets (more often than not arrays contain little elements, the JDK even acknowledges that e.g. most ArrayList stay empty for their whole lifetime which saves quite a bit of memory and CPU time for not instantiating arrays that will never be filled)

        And another anecdotal scenario: say if you implement some card game that needs sorting. Its embarassingly easy to parallelize multiple game executions next to each other instead of parallelizing the sorting mechanism of one run which may only take a fraction of the whole game loop. You lost an easy way to parallelize now.



        But yes, if you happen to have large arrays and sorting is a substantial part of your applications runtime use Arrays.parallelSort.



        EDIT:
        And even if Arrays.parallelSort switches to a normal sort if the given array has less than 4096 elements: it's all about showing intention - you want a parallel sort if possible which holds a different meaning than just calling sort. And to be nitpicky: it does indeed perform worse on small arrays as it has to do the additional check if the array is containing less than 4096 elements and some other checks about the common pools thread count (whichs overhead is of course negligible) :).






        share|improve this answer



























          9












          9








          9







          There are some downsides to using Arrays.parallelSort



          • it uses the ForkJoinPool.commonPool() and will fight with other functions that use it by default (e.g. parallel() on a stream)

          • the thread-pool Arrays.parallelSort uses is not configurable (only on a global level by increasing the common-pools thread amount)

          • it performs worse on small data sets (more often than not arrays contain little elements, the JDK even acknowledges that e.g. most ArrayList stay empty for their whole lifetime which saves quite a bit of memory and CPU time for not instantiating arrays that will never be filled)

          And another anecdotal scenario: say if you implement some card game that needs sorting. Its embarassingly easy to parallelize multiple game executions next to each other instead of parallelizing the sorting mechanism of one run which may only take a fraction of the whole game loop. You lost an easy way to parallelize now.



          But yes, if you happen to have large arrays and sorting is a substantial part of your applications runtime use Arrays.parallelSort.



          EDIT:
          And even if Arrays.parallelSort switches to a normal sort if the given array has less than 4096 elements: it's all about showing intention - you want a parallel sort if possible which holds a different meaning than just calling sort. And to be nitpicky: it does indeed perform worse on small arrays as it has to do the additional check if the array is containing less than 4096 elements and some other checks about the common pools thread count (whichs overhead is of course negligible) :).






          share|improve this answer















          There are some downsides to using Arrays.parallelSort



          • it uses the ForkJoinPool.commonPool() and will fight with other functions that use it by default (e.g. parallel() on a stream)

          • the thread-pool Arrays.parallelSort uses is not configurable (only on a global level by increasing the common-pools thread amount)

          • it performs worse on small data sets (more often than not arrays contain little elements, the JDK even acknowledges that e.g. most ArrayList stay empty for their whole lifetime which saves quite a bit of memory and CPU time for not instantiating arrays that will never be filled)

          And another anecdotal scenario: say if you implement some card game that needs sorting. Its embarassingly easy to parallelize multiple game executions next to each other instead of parallelizing the sorting mechanism of one run which may only take a fraction of the whole game loop. You lost an easy way to parallelize now.



          But yes, if you happen to have large arrays and sorting is a substantial part of your applications runtime use Arrays.parallelSort.



          EDIT:
          And even if Arrays.parallelSort switches to a normal sort if the given array has less than 4096 elements: it's all about showing intention - you want a parallel sort if possible which holds a different meaning than just calling sort. And to be nitpicky: it does indeed perform worse on small arrays as it has to do the additional check if the array is containing less than 4096 elements and some other checks about the common pools thread count (whichs overhead is of course negligible) :).







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 7 hours ago

























          answered 8 hours ago









          roookeeeroookeee

          7103 silver badges12 bronze badges




          7103 silver badges12 bronze badges























              2














              No, I would say no for small enough arrays. The overhead of setting up the threads won't result in an observable speed up.



              The key is "small enough". It won't be the same answer for all problems.



              Dogma should never be applied, except in the case of this dogma rule. Just like the only thing we should never tolerate is intolerance. There's a Popper paradox in there somewhere.






              share|improve this answer



























                2














                No, I would say no for small enough arrays. The overhead of setting up the threads won't result in an observable speed up.



                The key is "small enough". It won't be the same answer for all problems.



                Dogma should never be applied, except in the case of this dogma rule. Just like the only thing we should never tolerate is intolerance. There's a Popper paradox in there somewhere.






                share|improve this answer

























                  2












                  2








                  2







                  No, I would say no for small enough arrays. The overhead of setting up the threads won't result in an observable speed up.



                  The key is "small enough". It won't be the same answer for all problems.



                  Dogma should never be applied, except in the case of this dogma rule. Just like the only thing we should never tolerate is intolerance. There's a Popper paradox in there somewhere.






                  share|improve this answer













                  No, I would say no for small enough arrays. The overhead of setting up the threads won't result in an observable speed up.



                  The key is "small enough". It won't be the same answer for all problems.



                  Dogma should never be applied, except in the case of this dogma rule. Just like the only thing we should never tolerate is intolerance. There's a Popper paradox in there somewhere.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 8 hours ago









                  duffymoduffymo

                  275k38 gold badges325 silver badges514 bronze badges




                  275k38 gold badges325 silver badges514 bronze badges



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f56841334%2fis-there-ever-a-reason-not-to-use-java-8s-parallelsort%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

                      Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

                      199年 目錄 大件事 到箇年出世嗰人 到箇年死嗰人 節慶、風俗習慣 導覽選單