Oleksandr Oleksandr - 4 years ago 123
Java Question

Do not use System.out.println in server side code

I heard that using

for logging purposes is a very bad practice and this may force the server to fail.

I don't use this approach but I am very interested in knowing why System.out.println could make so trash things when used in backend code.

Answer Source

System.out.println is an IO-operation and therefor is time consuming. The Problem with using it in your code is, that your program will wait until the println has finished. This may not be a problem with small sites but as soon as you get load or many iterations, you'll feel the pain.

The better approach is to use a logging framework. They use a message queue and write only if no other output is going on.

And another benefit is that you can configure separate log files for different purposes. Something your Ops team will love you for.

Read more here:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download