package com.elab.core.componts;

import java.util.concurrent.CountDownLatch;

/**
 * @Module 加载工具类
 * @Description 判断应用是否加载完毕
 * @Author liukaixiong
 * @Date 2020/12/24 14:30
 */
public class LoadContextTool {

    private volatile boolean isLoadFinish = false;

    private CountDownLatch countDownLatch;

    public LoadContextTool(Integer countLatch) {
        this.countDownLatch = new CountDownLatch(countLatch);
    }

    public void awaitFinish() {
        if (!isLoadFinish) {
            try {
                countDownLatch.await();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public void loadFinish() {
        this.isLoadFinish = true;
        countDownLatch.countDown();
    }

}
