All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yqjr.framework.component.watcher.Watcher Maven / Gradle / Ivy

/**
 * 
 */
package com.yqjr.framework.component.watcher;

import org.springframework.util.Assert;

import com.yqjr.framework.component.log.Logger;

/**
 * ClassName: Watcher 
* Description: 监听者线程
* Create By: admin
* Create Date: 2017年7月5日 上午10:28:18
* Modified By:
* Modified Date:
* Modified Content:
* Version: 1.0
*/ public abstract class Watcher extends Thread { protected static long DEFAULT_DELAY = 60000; protected long delay = DEFAULT_DELAY; private boolean running = false; private static Logger logger = Logger.getLogger(); private String watcherName; public Watcher(String watcherName, long delay) { Assert.hasText(watcherName, "watcher name must be point out"); Assert.isTrue(delay > 1000, "watcher delay grant than 1000ms"); this.watcherName = watcherName; this.delay = delay; } public Watcher(String watcherName) { this(watcherName, DEFAULT_DELAY); } @Override public synchronized void start() { running = true; super.start(); logger.info(watcherName + "已启动"); } public synchronized void shutdown() { running = false; logger.info(watcherName + "已停止"); } /** * Description: 检查
* Create By: admin
* Create Date: 2017年7月5日 上午10:46:27 */ protected abstract void doCheck(); /** * Description: 变化时处理
* Create By: admin
* Create Date: 2017年7月5日 上午11:16:21 */ protected abstract void doOnChange(); @Override public void run() { while (running) { try { Thread.sleep(delay); } catch (InterruptedException e) { } doCheck(); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy