Does Java run any code for System.out.println(...) when I run the program in a console-less GUI? (where I don't redirect the program output to anywhere)
In fact I'd like to know if System.out.println(...) can affect the program performance when it is run by clicking the jar file.
Consider that I print thousands of lines per minute.
The way Java deals with calls, there probably will be significant impact if you println something that's not a simple string.
For example,
System.out.println("Iteration " + i);
creates a StringBuilder, converts an int and copies a bunch of characters before it can even decide that there is nothing behind System.out.
Let me put it this way.
If you were to execute you program from another program, then you would be able to read the stdout of your program, so yes, there is always something sent to stdout even if nothing is "listening"
From experience, we found there was an improvement in performance (under windows), if redirected the stdout and stderr thur a null stream (which consumed the streams), but we were dealing with a lot of output not just from our program but also the RMI server we were communicating with
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With