<commit_before>package main.design.pattern.singleton;

/**
 * Title : main.design.pattern.singleton
 * Description :
 *  - 单例模式有三个要点  一是某个类只能有一个实例
 *                      二是它必须自行创建这个实例
 *                      三是它必须自行向整个系统提供这个实例
 *
 * @author main.chile
 * @version 1.0
 * @date 2017/3/31 10:28
 */

public class TaskManager {

    private static TaskManager tm = null;

    private TaskManager() {}

    // -----------------------------------------------------------------------------------------------------------------
    /**
     * get singleton instance
     *
     * @return tm
     */
    public static TaskManager getInstance() {
        if (tm == null) {
            tm = new TaskManager();
        }
        return tm;
    }
    // -----------------------------------------------------------------------------------------------------------------

    public void displayProcesses() {}

    public void displayServices() {}

}<commit_msg>4 ways to get singleton instance.<commit_after>package main.design.pattern.singleton;

/**
 * Title : main.design.pattern.singleton <br>
 * Description : <br>
 *  - 单例模式有三个要点  一是某个类只能有一个实例
 *                      二是它必须自行创建这个实例
 *                      三是它必须自行向整个系统提供这个实例
 *
 * @author main.chile
 * @version 1.0
 * @date 2017/3/31 10:28
 */

public class TaskManager {

    private static TaskManager tm = null;

    private TaskManager() {}

    // -----------------------------------------------------------------------------------------------------------------
    /**
     * 1
     * get singleton instance
     * very not good, not safe
     * @return tm
     */
    public static TaskManager getInstance() {
        if (tm == null) {
            tm = new TaskManager();
        }
        return tm;
    }

    /**
     * 2
     * get singleton instance
     * @return tm
     */
    public static synchronized TaskManager getInstanceSynchronizedMethod() {
        if (tm == null) {
            tm = new TaskManager();
        }
        return tm;
    }

    /**
     * 3
     * get singleton instance synchronized
     * better than {@link #getInstanceSynchronizedMethod()}
     * @return tm
     */
    public static TaskManager getInstanceSynchronized() {
        if (null == tm) {
            synchronized (TaskManager.class) {
                if (null == tm) {
                    tm = new TaskManager();
                }
            }
        }
        return tm;
    }


    private static class InstanceHolder {
        private static final TaskManager INSTANCE = new TaskManager();
    }

    /**
     * 4
     * get singleton instance with inner static class
     * @return tm
     */
    public static TaskManager getInstanceWithInnerStaticClass() {
        return InstanceHolder.INSTANCE;
    }
    // -----------------------------------------------------------------------------------------------------------------

    public void displayProcesses() {}

    public void displayServices() {}

}
{'fraction_non_alphanumeric': 0.2379182156133829, 'fraction_numerical': 0.010476512335248395, 'mean_word_length': 1.1590080233406272, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2648610', 'n_tokens_mistral': 801, 'n_tokens_neox': 780, 'n_words': 185}