About synchronized in java.io.PrintStream

468 Views Asked by At

Does anybody know why the member call println of PrintStream is synchronized?

For example: public synchronized void println (String str)

But why there is no synchronized for public void println (char[] chars)?

1

There are 1 best solutions below

0
On

I have checked the given link

As per the method signature it says println(String) is synchronized and println(char[]) is not. However, when you read the description of println(char[]) it says it prints the string representation of the given char[] i.e. it implicitly converts the given char[] to String and calls the println(String) method.

So even though println(char[]) is not synchronized it achieves the synchronization implicitly by calling println(String).