Until you change the OutputStream through System.setOut , it is thread safe.
Although this is thread safe, you can have many threads writing to System.out to
Thread-1 System.out.println("A"); System.out.println("B"); System.out.println("C"); Thread-2 System.out.println("1"); System.out.println("2"); System.out.println("3");
can read
1 2 A 3 B C
among other combinations.
So, to answer your question:
When you write to System.out - it gets a lock on the OutputStream instance - it will be written to the buffer and hidden right away.
As soon as it releases the lock, the OutputStream is cleared and written. There would be no instance in which you would have different lines, such as 1A 2B .
Edit the answer to your edit:
This will not happen with System.out.println . Since PrintStream synchronizes the entire function, it fills the buffer and then flushes it atomically. Any new incoming stream will now have a new buffer for operation.
John Vint Feb 27 2018-12-12T00: 00Z
source share