| | |
| | | package com.nq.utils.task; |
| | | |
| | | |
| | | import com.nq.service.IEchoServices; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.concurrent.locks.ReentrantLock; |
| | | import java.util.concurrent.atomic.AtomicBoolean; |
| | | |
| | | /** |
| | | * 余额宝定时任务 |
| | | * */ |
| | | @Controller |
| | | */ |
| | | @Slf4j |
| | | @Component |
| | | public class YEBTask { |
| | | |
| | | |
| | | |
| | | @Autowired |
| | | IEchoServices echoServices; |
| | | private IEchoServices echoServices; |
| | | |
| | | private final ReentrantLock sendYEBMoneyLock = new ReentrantLock(); |
| | | private final AtomicBoolean isSendYEBMoney = new AtomicBoolean(false); |
| | | |
| | | /** |
| | | * 余额宝发放利息 |
| | | * */ |
| | | @Scheduled(cron = "0 0 0/1 * * ?") |
| | | public void sendYEBMoney(){ |
| | | echoServices.sendMoney(); |
| | | */ |
| | | // @Scheduled(cron = "0 0/1 * * * ?") |
| | | public void sendYEBMoney() { |
| | | if (isSendYEBMoney.get()) { // 判断任务是否在处理中 |
| | | return; |
| | | } |
| | | if (sendYEBMoneyLock.tryLock()) { // 尝试获取锁 |
| | | isSendYEBMoney.set(true); // 设置处理中标识为true |
| | | try { |
| | | log.info("基金定时任务-------开始"); |
| | | echoServices.sendMoney(); |
| | | log.info("基金定时任务-------结束"); |
| | | } finally { |
| | | sendYEBMoneyLock.unlock(); // 释放锁 |
| | | isSendYEBMoney.set(false); // 设置处理中标识为false |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |