package com.njzscloud.dispose.config;

import cn.hutool.core.util.RandomUtil;
import com.njzscloud.common.sichen.support.Task;
import com.njzscloud.common.sichen.support.TaskHandle;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@org.springframework.stereotype.Component
public class Example {

    @Task
    public void a() {
        Thread thread = Thread.currentThread();
        boolean virtual = thread.isVirtual();
        String name = thread.getName();
        TaskHandle.debug("A-------当前时间：{}  线程名称：{}  是否虚拟线程：{}", System.currentTimeMillis() / 1000, name, virtual);
        TaskHandle.info("A-------当前时间：{}  线程名称：{}  是否虚拟线程：{}", System.currentTimeMillis() / 1000, name, virtual);
        TaskHandle.warn("A-------当前时间：{}  线程名称：{}  是否虚拟线程：{}", System.currentTimeMillis() / 1000, name, virtual);
        TaskHandle.error(new RuntimeException("错误错误错误错误错误错误错误"), "A-------当前时间：{}  线程名称：{}  是否虚拟线程：{}", System.currentTimeMillis() / 1000, name, virtual);
        try {
            int sleepTime = RandomUtil.randomInt(1000, 5000);
            Thread.sleep(sleepTime);
        } catch (InterruptedException e) {
            log.error("任务中断退出", e);
        }
    }

  /*   @Task(period = 1)
    public void b() {
        log.info("B-------当前时间：{}", System.currentTimeMillis() / 1000);
    }

    @Task(period = 1)
    public void c() {
        log.info("C-------当前时间：{}", System.currentTimeMillis() / 1000);
    }

    @Task(cron = "0/1 * * * * ?")
    public void d() {
        log.info("D-------当前时间：{}", System.currentTimeMillis() / 1000);
    } */
}
