package com.njzscloud.common.sichen;

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

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

    @Task(period = 6)
    public void a() {
        Thread thread = Thread.currentThread();
        boolean virtual = thread.isVirtual();
        String name = thread.getName();
        log.info("A-------当前时间：{}  线程名称：{}  是否虚拟线程：{}", System.currentTimeMillis() / 1000, name, virtual);
        try {
            int sleepTime = RandomUtil.randomInt(1000, 5000);
            Thread.sleep(sleepTime);
        } catch (InterruptedException e) {
            throw new RuntimeException(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);
    }
}
