<commit_before>// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.logserver;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Logger;

import java.util.logging.Level;
import com.yahoo.logserver.handlers.LogHandler;

/**
 * @author <NAME>
 */
public class Flusher extends Thread {
    private static final Logger log = Logger.getLogger(Flusher.class.getName());
    private static final Flusher instance;
    private static final List<WeakReference<LogHandler>> logHandlers =
            new ArrayList<WeakReference<LogHandler>>();

    static {
        instance = new Flusher();
        instance.start();
    }

    Flusher() {
        super("flusher");
    }

    public static synchronized void register(LogHandler logHandler) {
        logHandlers.add(new WeakReference<>(logHandler));
    }

    public synchronized void run() {
        try {
            while(!isInterrupted()) {
                Thread.sleep(2000);
                Iterator<WeakReference<LogHandler>> it = logHandlers.iterator();
                while (it.hasNext()) {
                    WeakReference<LogHandler> r = it.next();
                    LogHandler h = r.get();
                    if (h == null) {
                        it.remove();
                    } else {
                        h.flush();
                    }
                    if (log.isLoggable(Level.FINE)) {
                        log.log(Level.FINE, "Flushing " + h);
                    }
                }
            }
        } catch (InterruptedException e) {
            log.log(Level.WARNING, "flusher was interrupted", e);
        }
    }
}<commit_msg>Sleep in end of iteration<commit_after>// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.logserver;

import com.yahoo.logserver.handlers.LogHandler;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * @author <NAME>
 */
public class Flusher extends Thread {
    private static final Logger log = Logger.getLogger(Flusher.class.getName());
    private static final Flusher instance;
    private static final List<WeakReference<LogHandler>> logHandlers =
            new ArrayList<WeakReference<LogHandler>>();

    static {
        instance = new Flusher();
        instance.start();
    }

    Flusher() {
        super("flusher");
    }

    public static synchronized void register(LogHandler logHandler) {
        logHandlers.add(new WeakReference<>(logHandler));
    }

    @Override
    public synchronized void run() {
        try {
            while(!isInterrupted()) {
                Iterator<WeakReference<LogHandler>> it = logHandlers.iterator();
                while (it.hasNext()) {
                    WeakReference<LogHandler> r = it.next();
                    LogHandler h = r.get();
                    if (h == null) {
                        it.remove();
                    } else {
                        h.flush();
                    }
                    if (log.isLoggable(Level.FINE)) {
                        log.log(Level.FINE, "Flushing " + h);
                    }
                }
                Thread.sleep(2000);
            }
        } catch (InterruptedException e) {
            log.log(Level.WARNING, "flusher was interrupted", e);
        }
    }
}
{'fraction_non_alphanumeric': 0.10726164079822616, 'fraction_numerical': 0.005543237250554324, 'mean_word_length': 1.8507109004739337, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3952343', 'n_tokens_mistral': 988, 'n_tokens_neox': 931, 'n_words': 231}