/**
 * Copyright 2008-2009. Chongqing Communications Industry Services Co.,Ltd Information Technology Branch. All rights reserved. <a>http://www.crunii.com</a>
 */
package com.crunii.micro.common.utils;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;

import lombok.extern.slf4j.Slf4j;

/**
 * @author 田平 create 2017年10月16日上午11:29:47
 */
@Slf4j
public class StopUtil {

	public static void stopES(ExecutorService es) {
		stopES(es, 30, TimeUnit.SECONDS);
	}

	public static void stopES(ExecutorService es, long timeout, TimeUnit unit) {
		if (es != null) {
			try {
				es.shutdown();
				if (!es.awaitTermination(timeout, unit)) {
					es.shutdownNow();
				}
			} catch (InterruptedException e) {
				log.error("awaitTermination interrupted: " + e);
				es.shutdownNow();
			}
		}
	}

}
