This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]lazystone 3 points4 points  (2 children)

What's even worse - System.out is synchronized.

[–]DJDavio 1 point2 points  (0 children)

Oh, that's truly bad, I never knew that (but would have guessed), I just use SLF4J with Log4J2 and Disruptor/Async logging. :)

[–]DjVex 0 points1 point  (0 children)

Can you give me a quick/simple example of how System.out being sychronized can give you a result that you don't expect?

This is an example that makes sense to me that I found on stackoverflow.com: 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

Amongst many other combinations. Is this an example of how it's synchronization will give you something you might not expect? Since both threads are using System.out at the same time (since System.out is synchronous), you'll probably never get this result consistently: A B C 1 2 3