• 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); } }
  • 相关阅读:
    Brighter3d无法渲染可导入REVIT渲染
    屏蔽优酷等视频网站片头广告
    REVIT机电管线支架族的创建
    如何显示链接的REVIT模型中的注释文字
    REVIT参数化自适应多边形拉伸
    REVIT族管理插件project family brower
    使用VMware虚拟磁盘管理工具调整磁盘大小
    硬件兼容性的陷阱,DrawIndexedPrimitiveUP的用法
    第二章 伤寒之意义(1)
    可变参数函数设计
  • 原文地址:https://www.cnblogs.com/eaglediao/p/6895975.html
Copyright © 2020-2023  润新知