Questions about Stream/Iterable/Files - and possibly the compiler
Fabrizio.Giudici at tidalwave.it
Fri Nov 6 18:58:42 UTC 2015
On Fri, 06 Nov 2015 14:39:29 +0100, Paul Sandoz <paul.sandoz at oracle.com>
>> On 6 Nov 2015, at 14:19, Fabrizio Giudici
>> <fabrizio.giudici at tidalwave.it> wrote:
>>> I logged an issue:
>> Thanks to Remi and Paul for the complete explanation. Concerning
>> JDK-8141608, I lile Peter Levart's comment about making a specific
> There is a problem with that approach. At the moment the Collector does
> not get to control whether the stream is executed in parallel or
Sure, I understand. I think it would be ok if the Collector has as a
pre-requisite that it can't be used with a parallel Stream. I assume that
if the stream is not parallel, the runtime won't ever try to execute the
Collector in parallel... right? That's what I see from the tests I've
executed so far.
I've tried to write such a FileCollector, with a check that throws an
exception if the accumulator Supplier function is called more than once,
with code such as:
private final AtomicBoolean parallelChecker = new AtomicBoolean();
public Supplier<PrintWriter> supplier()
private PrintWriter oneShotPrintWriterSupplier()
It seems to properly detect when it's called with a parallel Stream. Do
you think that it's safe enough?
Fabrizio Giudici - Java Architect @ Tidalwave s.a.s.
"We make Java work. Everywhere."
http://tidalwave.it/fabrizio/blog - fabrizio.giudici at tidalwave.it
More information about the core-libs-dev