https://issues.apache.org/bugzilla/show_bug.cgi?id=54777

--- Comment #3 from Mikhail Epikhin <[email protected]> ---
(In reply to comment #2)
> Thanks for the suggested patch. I'm not clear why the code should be better
> than PrintWriter.println() - this ought to be explained in the Javadoc.

1. Because real write is "async" opertation by Sampler, which running it in my
code.

With simple autoFlush=true, everytime when you use println(), you alse call
flush-ethod.

Just look at OpenJDK 1.7

println(String s)
(http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7-b147/java/io/PrintWriter.java?av=f
) 
  |                  \
  v                   v
print(String s)       println()
(http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7-b147/java/io/PrintWriter.java#PrintWriter.println%28%29)
                        |
                        v
                     newLine() -> out.flush()
(http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7-b147/java/io/PrintWriter.java#PrintWriter.newLine%28%29)


Soo, when you use autoFlush=true, println(), and many threads, u also have very
poor performance.

Single flush method make context switch to kernel-thread, and his make real
write-method. This is blocking operation. 
If i separate println() operation from Sampler Thread and flush() method to
another thread, it make better performance. Sample Thread don't wait real flush
on disk. He just do him-self job. Not write to log.

2. Decrease flush operation counts

> There are some problems with the code as it stands:
> 
> The field lineSeparator cannot be fixed as '\n', as that is not portable.
> 

Sorry, i look at PrintWriter.lineSeparator by OpenJDK and did it as well
http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7-b147/java/io/PrintWriter.java#PrintWriter.0lineSeparator

Any solutions for portable?

> Constructors should not start threads - there is no guarantee that the class
> will have been fully constructed before the thread tries accessing it.

If fluhs-thread not started, real buffer in super() will be constructured and
another threads make println() operations, but in real, without flush, while
flush-thread not started.

> A couple of minor style issues: we don't generally allow multiple statements
> per line.
> Aslo we always use blocks in conditional statements.

Okey, it's not a problem.

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to