zoukankan      html  css  js  c++  java
  • quatz调度-手动终止线程(2) Cleaner线程做清理工作

    import java.util.concurrent.ArrayBlockingQueue;
    import java.util.concurrent.BlockingQueue;
    import java.util.concurrent.Executors;
    
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    
    import com.tdtech.eplatform.gatekeeper.quartz.QuartzCenter;
    import com.tdtech.eplatform.gatekeeper.util.ContextUtil;
    
    public class Cleaner {
        public static Cleaner insance = new Cleaner();
        private BlockingQueue<String> list = new ArrayBlockingQueue<String>(2000);
        java.util.concurrent.Executor executor = Executors.newFixedThreadPool(1);
        private Logger logger = LoggerFactory.getLogger(Cleaner.class);
        private QuartzCenter quart;
    
        public static Cleaner getInstance() {
            return insance;
        }
    
        private Cleaner() {
            Runnable task = new Runnable() {
    
                @Override
                public void run() {
    
                    try {
                        while (true) {
                            logger.info("before clean");
                            String jobName = list.take();
                            logger.info("cleanJobName:" + jobName);
                            if (quart == null) {
                                quart = ContextUtil.getBean("quartzCenter", QuartzCenter.class);
                      /*
                             private static ClassPathXmlApplicationContext applicationContext;

                              public static <T> T getBean(String name, Class<T> requiredType) {
                              try {
                                    return applicationContext.getBean(name, requiredType);
                                } catch (Exception e) {
                                      logger.error("I wanna get " + name, e);
                                      return null;
                                 }
                             }


                      */ }
    if (quart != null) {
                     // 终止线程 quart.terminateJob(jobName); logger.info(
    "after cleanJobName.Done:" + jobName); } } } catch (InterruptedException e) { logger.error("InterruptedException", e); } } }; executor.execute(task);
         // sumit区别 需要返回执行结果。      // Future future = execute.submit(task); } /**
      加入队列以便cleaner处理
      */
    public void put(String name) { list.offer(name); } }
  • 相关阅读:
    org.apache.catalina.mbeans.ServerLifecycleListener
    模拟log4j获取日志对象调用所在的类名、方法名及行号
    菜鸟从零学编程(八)——将MyEclipse项目导入到Eclipse
    Oracle DB 使用调度程序自动执行任务
    无线网卡的查看与配置——iw,iwconfig,ethtool
    如何从iTunes Connect中提款呢?
    tomcat解压war包的一点例外
    Shared File System Master Slave 全配置以及测试
    [置顶] “欢子说事”微信公众平台上线,做大学生第一交流平台
    android编程之ExpandableListView使用总结
  • 原文地址:https://www.cnblogs.com/eaglediao/p/6895975.html
Copyright © 2011-2022 走看看