| | |
| | | |
| | | private String name; |
| | | private AtomicBoolean stopRequested; |
| | | private WriterThread writerThread; |
| | | private final WriterThread writerThread; |
| | | |
| | | private boolean autoFlush; |
| | | |
| | |
| | | |
| | | this.queue = new LinkedBlockingQueue<>(capacity); |
| | | this.capacity = capacity; |
| | | this.writerThread = null; |
| | | this.stopRequested = new AtomicBoolean(false); |
| | | |
| | | writerThread = new WriterThread(); |
| | | writerThread.start(); |
| | | |
| | | DirectoryServer.registerShutdownListener(this); |
| | | } |
| | | |
| | | /** |
| | | * Starts the background thread which publishes the queued log records. |
| | | * <p> |
| | | * The thread is not started by the constructor so that {@code this} is not published to it before |
| | | * construction has completed. |
| | | * |
| | | * @return this writer |
| | | */ |
| | | AsynchronousTextWriter start() |
| | | { |
| | | writerThread.start(); |
| | | return this; |
| | | } |
| | | |
| | | /** |
| | | * The publisher thread is responsible for emptying the queue of log records |
| | | * waiting to published. |
| | | */ |
| | |
| | | stopRequested.set(true); |
| | | |
| | | // Wait for publisher thread to terminate |
| | | while (writerThread != null && writerThread.isAlive()) { |
| | | while (writerThread.isAlive()) { |
| | | try { |
| | | // Interrupt the thread if its blocking |
| | | writerThread.interrupt(); |