Class AsyncDrainWriter
java.lang.Object
org.apache.maven.logging.AsyncDrainWriter
- All Implemented Interfaces:
AutoCloseable, Consumer<String>
A lock-free buffering wrapper around a
Consumer<String> that
eliminates contention when multiple threads log concurrently.
Callers enqueue messages into a ConcurrentLinkedQueue (lock-free),
then attempt a non-blocking drain via ReentrantLock.tryLock().
If another thread is already draining, the caller returns immediately —
its message will be picked up by the ongoing or next drain cycle.
This ensures that at most one thread writes to the underlying consumer
at any time, without blocking producers.
The pattern eliminates the synchronized contention in
PrintWriter.println(String) that occurs when multiple
PhasingExecutor threads log during
parallel model building.
- Since:
- 4.0.0
-
Constructor Details
-
AsyncDrainWriter
-
-
Method Details
-
accept
-
close
public void close()Flushes all remaining buffered messages to the delegate. Blocks until the drain is complete — call this before shutdown to ensure no messages are lost.- Specified by:
closein interfaceAutoCloseable
-