When I was starting study Java, I was being told not to do System.out.println in Java EE application. However I don't really know what is the reason of not doing so.
I am fully aware that if we really need to print an important, it should be logged using logging framework.
What I really want to ask here : is there any real hazard that System.out.println make? Does it cause any performance issue?
out. println is a Java statement that prints the argument passed, into the System. out which is generally stdout. System is a Class. out is a Variable.
Since System. out. println() is not a field declaration, it's not allowed.
println() is used to print an argument that is passed to it. The statement can be broken into 3 parts which can be understood separately as: System: It is a final class defined in the java. lang package. out: This is an instance of PrintStream type, which is a public and static member field of the System class.
It's indeed a performance issue. If you dig down into the JDK source code for System.out
you'll eventually encounter a synchronized
block on the output stream.
That means that if you put enough println calls in your source code, the entire code base will effectively run single-threaded, because all threads are waiting for the synchronization lock.
There are some statistics involved here, a single call to println generally isn't going to bring your entire application to a crawl. The more println calls in your code, the more likely two or more threads will have to wait for eachother.
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