package com.nms.server.thread.change;

import java.util.concurrent.Future;

import org.apache.log4j.Logger;

import com.nms.server.common.Common;
import com.nms.server.common.Constants;


/**
 *  周期性检查数据库，将检索变更通讯并下发
 *  @date Mar 31, 2012 10:03:04 AM
 *	@author ZhangGang
 *
 */
public class ChangeManagerThread implements Runnable{
	Logger logger = Logger.getLogger(ChangeManagerThread.class);

	@Override
	public void run() {
		//将线程运行程序，尽可能的catch捕获异常
		try {
//			Thread.currentThread().setName("变更操作管理线程");
			Thread.currentThread().setName("Changing The Operation Management Thread");

			Future<?> future = Common.getFutureMap().get(Constants.CHANGE_OPERATIONS);
			
			if(future != null && !future.isCancelled() && !future.isDone()){	//运行中
				logger.info("变更操作线程 运行中 不再启动新线程");
			}else{	
				//为空或空闲中
				logger.info("变更操作线程 空闲中 启动新线程");
//				future = Common.service.submit(new ChangeThread("变更操作线程"));
				future = Common.service.submit(new ChangeThread("Changing The Operating Thread"));
				//注册
				Common.getFutureMap().put(Constants.CHANGE_OPERATIONS, future);
			}
		} catch (Exception e) {
			logger.error("",e);
		}
	}

	
}
