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

--- Comment #4 from Sebb <[email protected]> ---
(In reply to comment #3)
> (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.

OK, then this needs to be documented in the code.

Since the only function of the thread seems to be to run flush every so often,
I wonder if a separate thread is really needed?

Perhaps a simple decorator would suffice.
That would solve the issue of how to start the thread safely.

> > 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

No, it does not.

It does not fix lineSeparator as the single char '\n'.

> Any solutions for portable?

Use the value of the property "line.separator" which is a String (e.g. it might
be \r\n")

> > 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.

Yes, but the ctor still must not start a thread.
You need to find a way to start the thread after construction.

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

Reply via email to