package com.dy.common.mw.core; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; /** * @Author liurunyu * @Date 2023/12/19 16:41 * @LastEditTime 2023/12/19 16:41 * @Description */ public class CoreConstantThread extends Thread { private final static Logger log = LogManager.getLogger(CoreConstantThread.class.getName()) ; private long sleepBigBusy ; private long sleepSmallBusy ; private CoreTask task ; public CoreConstantThread(long sleepBigBusy, long sleepSmallBusy, CoreTask task){ this.sleepBigBusy = sleepBigBusy ; this.sleepSmallBusy = sleepSmallBusy ; this.task = task ; } @Override public void run() { if(task != null){ int count ; while (true) { try { count = task.execute(); if (count == 0) { //小暂停一下 Thread.sleep(sleepBigBusy); }else{ Thread.sleep(sleepSmallBusy); } } catch (Exception e) { log.error("恒久任务" + task.getClass().getName() + "执行时发生异常" + (e.getMessage() == null ? "" : (":" + e.getMessage())), e); } } } } }