package com.bpa.scalage.HBL;



import com.bpa.scalage.HBL.Interface.IRun;
import com.bpa.scalage.HBL.Logs.MessageLog;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 异步方法
 */
public class Executor {

    private static Executor mInstance; //实例变量设置私有，防止直接通过类名访问

    private Executor() { //默认构造函数私有，防止类外直接new创建对象
    }

    public static synchronized Executor get() { //静态同步方法作为唯一的实例对象获取方式
        if (mInstance == null) {
            mInstance = new Executor();
        }
        return mInstance;
    }
    private ExecutorService executor= Executors.newCachedThreadPool() ;

    public void runThread(IRun run)  {
        executor.submit(new Runnable(){
            @Override
            public void run() {
                try {
                    if(run!=null)run.Run();
                }catch(Exception ex) {
                    MessageLog.ShowError("runThread 异常："+ex.getMessage());
                }
            }
        });
    }


}
