Home:ALL Converter>Infinite while loop : Java or Shell script

Infinite while loop : Java or Shell script

Ask Time:2017-01-05T15:29:26         Author:Shreyank Shah

Json Formatter

I would like to execute Java code infinite times through shell script. And for that I have two options.

  1. Infinitely call Java class in Shell script using while loop
  2. Infinite while loop in Java class code and call Java class once in Shell script

Which is the better way to do it?

Author:Shreyank Shah,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/41479462/infinite-while-loop-java-or-shell-script
GhostCat again on strike :

Technical facts based answer: \n\nhaving the loop in your shell script means that you keep constantly starting new JVM processes. That will put a higher load on your system compared to having a loop within the Java program you are executing.\n\nIn other words: you start one JVM session, it does something; it goes down; the next starts ... forever.\n\nProbably Linux is doing a lot of things behind the cover that reduce the cost of doing so (for example by actually keeping things in memory); but still: you are constantly starting processes to end them soon thereafter. \n\nIf you really intend to run your code for an \"infinite\" time; than you definitely want to avoid wasting resources in any form.\n\nThat on the other hand, can give a (weak) argument for keeping the loop on the script side: when you put your loop into your java code, and your java code is actually buggy (memory leaks for example); then the memory consumption of that one JVM could keep growing forever (until reaching its limit; and then you might see a lot of garbage collection). \n\nMeaning: when you know that your Java code is in a bad shape; and that running it in the same JVM over longer periods of time causes problems; then of course: starting and stopping the JVM has some benefits. \nBut of course - in that case, you have some bigger problem anyway. If your java application has such problems, then you better identify their root cause and fix them; instead of constantly starting/stopping your JVM to circumvent these issues.",
2017-01-05T07:37:41
yy