Running while loop infinitely without any code inside in java

Multi tool use
Multi tool use












1















Lets say I have written a infinite write loop but didn't have statement inside it? Will it create any issue like memory will be full etc or JVM will stop responding after sometime?










share|improve this question




















  • 1





    what do you mean by an infinite write loop?

    – Uku Loskit
    Dec 28 '18 at 20:45






  • 1





    @UkuLoskit read the subject line

    – Joakim Danielson
    Dec 28 '18 at 20:46











  • Possible duplicate of Empty infinite loop and GC (JVM). Please explain the effect

    – oleg.cherednik
    Dec 28 '18 at 21:04
















1















Lets say I have written a infinite write loop but didn't have statement inside it? Will it create any issue like memory will be full etc or JVM will stop responding after sometime?










share|improve this question




















  • 1





    what do you mean by an infinite write loop?

    – Uku Loskit
    Dec 28 '18 at 20:45






  • 1





    @UkuLoskit read the subject line

    – Joakim Danielson
    Dec 28 '18 at 20:46











  • Possible duplicate of Empty infinite loop and GC (JVM). Please explain the effect

    – oleg.cherednik
    Dec 28 '18 at 21:04














1












1








1








Lets say I have written a infinite write loop but didn't have statement inside it? Will it create any issue like memory will be full etc or JVM will stop responding after sometime?










share|improve this question
















Lets say I have written a infinite write loop but didn't have statement inside it? Will it create any issue like memory will be full etc or JVM will stop responding after sometime?







java






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 28 '18 at 20:50









Karol Dowbecki

18.9k92850




18.9k92850










asked Dec 28 '18 at 20:43









NirmeshNirmesh

57310




57310








  • 1





    what do you mean by an infinite write loop?

    – Uku Loskit
    Dec 28 '18 at 20:45






  • 1





    @UkuLoskit read the subject line

    – Joakim Danielson
    Dec 28 '18 at 20:46











  • Possible duplicate of Empty infinite loop and GC (JVM). Please explain the effect

    – oleg.cherednik
    Dec 28 '18 at 21:04














  • 1





    what do you mean by an infinite write loop?

    – Uku Loskit
    Dec 28 '18 at 20:45






  • 1





    @UkuLoskit read the subject line

    – Joakim Danielson
    Dec 28 '18 at 20:46











  • Possible duplicate of Empty infinite loop and GC (JVM). Please explain the effect

    – oleg.cherednik
    Dec 28 '18 at 21:04








1




1





what do you mean by an infinite write loop?

– Uku Loskit
Dec 28 '18 at 20:45





what do you mean by an infinite write loop?

– Uku Loskit
Dec 28 '18 at 20:45




1




1





@UkuLoskit read the subject line

– Joakim Danielson
Dec 28 '18 at 20:46





@UkuLoskit read the subject line

– Joakim Danielson
Dec 28 '18 at 20:46













Possible duplicate of Empty infinite loop and GC (JVM). Please explain the effect

– oleg.cherednik
Dec 28 '18 at 21:04





Possible duplicate of Empty infinite loop and GC (JVM). Please explain the effect

– oleg.cherednik
Dec 28 '18 at 21:04












3 Answers
3






active

oldest

votes


















1














Why would you do something like that?



To answer, it wouldn't consume endless memory but Cpu usage could be a pain with really no instruction at all.



At minimum, you should help CPU preemption allowing the Thread to yield:



Thread.yield();


You can read this in Java Api Javadoc:




A hint to the scheduler that the current thread is willing to yield its current use of a processor. The scheduler is free to ignore this hint.



Yield is a heuristic attempt to improve relative progression between threads that would otherwise over-utilise a CPU. Its use should be combined with detailed profiling and benchmarking to ensure that it actually has the desired effect.



It is rarely appropriate to use this method. It may be useful for debugging or testing purposes, where it may help to reproduce bugs due to race conditions. It may also be useful when designing concurrency control constructs such as the ones in the java.util.concurrent.locks package.







share|improve this answer


























  • @Nirmesh On Stackoverflow you can give up-vote to people's helpful answers to thank them and select any one of the answer as correct answer too out of all.

    – Bsquare
    2 days ago



















0














An infinite loop might and probably will result in 100% CPU core utilization. Depending what you mean by "write loop" a similar technique is called Busy Waiting or Spinning.




spinning as a time delay technique often produces unpredictable or even inconsistent results unless code is implemented to determine how quickly the processor can execute a "do nothing" loop, or the looping code explicitly checks a real-time clock







share|improve this answer































    0














    You'll certainly keep one hardware thread busy. It wont create any objects, so memory isn't a direct issue as such.



    However, the context is important.




    • If it is a high priority thread, the system may become unresponsive. This is implementation specific. Twenty years ago I wrote an infinite loop that made a Windows NT system unresponsive. (I think this was a TCP proxy and only happened when an IBM 3090 running CICS sent an empty keep alive frame to a 3270 terminal. Good times.)

    • If the thread is holding any locks, that wont be released.

    • If the thread does something useful, that useful thing wont happen. For instance if you were to write the loop in a finaliser (and the system only has one finaliser thread), no other object will get finalised and therefore not garbage collected either. The application may behave peculiarly. It'salways fun to run random code on the finaliser thread.






    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%2f53964094%2frunning-while-loop-infinitely-without-any-code-inside-in-java%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      Why would you do something like that?



      To answer, it wouldn't consume endless memory but Cpu usage could be a pain with really no instruction at all.



      At minimum, you should help CPU preemption allowing the Thread to yield:



      Thread.yield();


      You can read this in Java Api Javadoc:




      A hint to the scheduler that the current thread is willing to yield its current use of a processor. The scheduler is free to ignore this hint.



      Yield is a heuristic attempt to improve relative progression between threads that would otherwise over-utilise a CPU. Its use should be combined with detailed profiling and benchmarking to ensure that it actually has the desired effect.



      It is rarely appropriate to use this method. It may be useful for debugging or testing purposes, where it may help to reproduce bugs due to race conditions. It may also be useful when designing concurrency control constructs such as the ones in the java.util.concurrent.locks package.







      share|improve this answer


























      • @Nirmesh On Stackoverflow you can give up-vote to people's helpful answers to thank them and select any one of the answer as correct answer too out of all.

        – Bsquare
        2 days ago
















      1














      Why would you do something like that?



      To answer, it wouldn't consume endless memory but Cpu usage could be a pain with really no instruction at all.



      At minimum, you should help CPU preemption allowing the Thread to yield:



      Thread.yield();


      You can read this in Java Api Javadoc:




      A hint to the scheduler that the current thread is willing to yield its current use of a processor. The scheduler is free to ignore this hint.



      Yield is a heuristic attempt to improve relative progression between threads that would otherwise over-utilise a CPU. Its use should be combined with detailed profiling and benchmarking to ensure that it actually has the desired effect.



      It is rarely appropriate to use this method. It may be useful for debugging or testing purposes, where it may help to reproduce bugs due to race conditions. It may also be useful when designing concurrency control constructs such as the ones in the java.util.concurrent.locks package.







      share|improve this answer


























      • @Nirmesh On Stackoverflow you can give up-vote to people's helpful answers to thank them and select any one of the answer as correct answer too out of all.

        – Bsquare
        2 days ago














      1












      1








      1







      Why would you do something like that?



      To answer, it wouldn't consume endless memory but Cpu usage could be a pain with really no instruction at all.



      At minimum, you should help CPU preemption allowing the Thread to yield:



      Thread.yield();


      You can read this in Java Api Javadoc:




      A hint to the scheduler that the current thread is willing to yield its current use of a processor. The scheduler is free to ignore this hint.



      Yield is a heuristic attempt to improve relative progression between threads that would otherwise over-utilise a CPU. Its use should be combined with detailed profiling and benchmarking to ensure that it actually has the desired effect.



      It is rarely appropriate to use this method. It may be useful for debugging or testing purposes, where it may help to reproduce bugs due to race conditions. It may also be useful when designing concurrency control constructs such as the ones in the java.util.concurrent.locks package.







      share|improve this answer















      Why would you do something like that?



      To answer, it wouldn't consume endless memory but Cpu usage could be a pain with really no instruction at all.



      At minimum, you should help CPU preemption allowing the Thread to yield:



      Thread.yield();


      You can read this in Java Api Javadoc:




      A hint to the scheduler that the current thread is willing to yield its current use of a processor. The scheduler is free to ignore this hint.



      Yield is a heuristic attempt to improve relative progression between threads that would otherwise over-utilise a CPU. Its use should be combined with detailed profiling and benchmarking to ensure that it actually has the desired effect.



      It is rarely appropriate to use this method. It may be useful for debugging or testing purposes, where it may help to reproduce bugs due to race conditions. It may also be useful when designing concurrency control constructs such as the ones in the java.util.concurrent.locks package.








      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Dec 28 '18 at 21:17

























      answered Dec 28 '18 at 20:47









      BsquareBsquare

      3,20731033




      3,20731033













      • @Nirmesh On Stackoverflow you can give up-vote to people's helpful answers to thank them and select any one of the answer as correct answer too out of all.

        – Bsquare
        2 days ago



















      • @Nirmesh On Stackoverflow you can give up-vote to people's helpful answers to thank them and select any one of the answer as correct answer too out of all.

        – Bsquare
        2 days ago

















      @Nirmesh On Stackoverflow you can give up-vote to people's helpful answers to thank them and select any one of the answer as correct answer too out of all.

      – Bsquare
      2 days ago





      @Nirmesh On Stackoverflow you can give up-vote to people's helpful answers to thank them and select any one of the answer as correct answer too out of all.

      – Bsquare
      2 days ago













      0














      An infinite loop might and probably will result in 100% CPU core utilization. Depending what you mean by "write loop" a similar technique is called Busy Waiting or Spinning.




      spinning as a time delay technique often produces unpredictable or even inconsistent results unless code is implemented to determine how quickly the processor can execute a "do nothing" loop, or the looping code explicitly checks a real-time clock







      share|improve this answer




























        0














        An infinite loop might and probably will result in 100% CPU core utilization. Depending what you mean by "write loop" a similar technique is called Busy Waiting or Spinning.




        spinning as a time delay technique often produces unpredictable or even inconsistent results unless code is implemented to determine how quickly the processor can execute a "do nothing" loop, or the looping code explicitly checks a real-time clock







        share|improve this answer


























          0












          0








          0







          An infinite loop might and probably will result in 100% CPU core utilization. Depending what you mean by "write loop" a similar technique is called Busy Waiting or Spinning.




          spinning as a time delay technique often produces unpredictable or even inconsistent results unless code is implemented to determine how quickly the processor can execute a "do nothing" loop, or the looping code explicitly checks a real-time clock







          share|improve this answer













          An infinite loop might and probably will result in 100% CPU core utilization. Depending what you mean by "write loop" a similar technique is called Busy Waiting or Spinning.




          spinning as a time delay technique often produces unpredictable or even inconsistent results unless code is implemented to determine how quickly the processor can execute a "do nothing" loop, or the looping code explicitly checks a real-time clock








          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 28 '18 at 20:47









          Karol DowbeckiKarol Dowbecki

          18.9k92850




          18.9k92850























              0














              You'll certainly keep one hardware thread busy. It wont create any objects, so memory isn't a direct issue as such.



              However, the context is important.




              • If it is a high priority thread, the system may become unresponsive. This is implementation specific. Twenty years ago I wrote an infinite loop that made a Windows NT system unresponsive. (I think this was a TCP proxy and only happened when an IBM 3090 running CICS sent an empty keep alive frame to a 3270 terminal. Good times.)

              • If the thread is holding any locks, that wont be released.

              • If the thread does something useful, that useful thing wont happen. For instance if you were to write the loop in a finaliser (and the system only has one finaliser thread), no other object will get finalised and therefore not garbage collected either. The application may behave peculiarly. It'salways fun to run random code on the finaliser thread.






              share|improve this answer




























                0














                You'll certainly keep one hardware thread busy. It wont create any objects, so memory isn't a direct issue as such.



                However, the context is important.




                • If it is a high priority thread, the system may become unresponsive. This is implementation specific. Twenty years ago I wrote an infinite loop that made a Windows NT system unresponsive. (I think this was a TCP proxy and only happened when an IBM 3090 running CICS sent an empty keep alive frame to a 3270 terminal. Good times.)

                • If the thread is holding any locks, that wont be released.

                • If the thread does something useful, that useful thing wont happen. For instance if you were to write the loop in a finaliser (and the system only has one finaliser thread), no other object will get finalised and therefore not garbage collected either. The application may behave peculiarly. It'salways fun to run random code on the finaliser thread.






                share|improve this answer


























                  0












                  0








                  0







                  You'll certainly keep one hardware thread busy. It wont create any objects, so memory isn't a direct issue as such.



                  However, the context is important.




                  • If it is a high priority thread, the system may become unresponsive. This is implementation specific. Twenty years ago I wrote an infinite loop that made a Windows NT system unresponsive. (I think this was a TCP proxy and only happened when an IBM 3090 running CICS sent an empty keep alive frame to a 3270 terminal. Good times.)

                  • If the thread is holding any locks, that wont be released.

                  • If the thread does something useful, that useful thing wont happen. For instance if you were to write the loop in a finaliser (and the system only has one finaliser thread), no other object will get finalised and therefore not garbage collected either. The application may behave peculiarly. It'salways fun to run random code on the finaliser thread.






                  share|improve this answer













                  You'll certainly keep one hardware thread busy. It wont create any objects, so memory isn't a direct issue as such.



                  However, the context is important.




                  • If it is a high priority thread, the system may become unresponsive. This is implementation specific. Twenty years ago I wrote an infinite loop that made a Windows NT system unresponsive. (I think this was a TCP proxy and only happened when an IBM 3090 running CICS sent an empty keep alive frame to a 3270 terminal. Good times.)

                  • If the thread is holding any locks, that wont be released.

                  • If the thread does something useful, that useful thing wont happen. For instance if you were to write the loop in a finaliser (and the system only has one finaliser thread), no other object will get finalised and therefore not garbage collected either. The application may behave peculiarly. It'salways fun to run random code on the finaliser thread.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 28 '18 at 21:32









                  Tom Hawtin - tacklineTom Hawtin - tackline

                  125k28180271




                  125k28180271






























                      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%2f53964094%2frunning-while-loop-infinitely-without-any-code-inside-in-java%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







                      uIYer0oEf ICN3vZ IP a1hQ4c 2P9dIZEBvRN8fJLQEoEZ4BW0n9dum14iSnWj qOHLe2OFcRJtljydYmZDTY hys3RMFpxmcqam,L
                      C2YJT,pbJcyMOWULPjJbd 2Pd R6mjqCxGITfmo knH,nSCUGpwZXl385kZ5OPAL5KS9GMtIZ1RBsjcAGjTq8Jmf2,wzn Iwo1i5

                      Popular posts from this blog

                      Monofisismo

                      Angular Downloading a file using contenturl with Basic Authentication

                      Olmecas