java定时器第n个工作日_Spring 定时器低版本不支持“L”的cron表达式 每个月的最后一个工作日的另一种解法...

/**

* 判断今天是不是本月的最后一个工作日

*/

public void checkLastWorkDay() {

Calendar cal1 = Calendar.getInstance();

int month = cal1.get(Calendar.MONTH) + 1;

int year = cal1.get(Calendar.YEAR);

int day = cal1.get(Calendar.DATE);

logger.warn(year + "年" + month + "月" + day + "日");

Calendar cal = Calendar.getInstance();

cal.set(Calendar.YEAR, year);

cal.set(Calendar.MONTH, month - 1);

int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);// 获取该月最大一天

cal.set(Calendar.DAY_OF_MONTH, lastDay);

if (day == lastDay) {

logger.warn("今天是本月的最后一天");

SpringJobUtil.updateNewEndMonthOrg();

} else {

logger.warn("今天不是本月的最后一天");

}

}

/**

* 月底生成一份最新的编制到一个表里

*/

public static void updateNewEndMonthOrg(){

if (isIp()) {

String lockName = ConstantCommon.REDIS_LOCK.UPDATE_NEWEST_ORG_TASK_LOCK;

int expireSecond = 3600;// 秒

boolean flag = RedisShardedPoolUtil.redisClock(lockName, expireSecond);

if (flag) {

RedisShardedPoolUtil.expire(lockName, expireSecond);// 有效期expireSecond秒,防止死锁

System.out.println("获取" + lockName + ",ThreadName:" + Thread.currentThread());

System.out.println("-------执行生成一份最新的编制到一个表里begin--------------");

for (OrgEntity tenant : ConstantCommon.LIST_TENANT) {

DynamicDataSourceHolder.setDataSourceType(tenant.getOrgId());

if (logger.isDebugEnabled()) {

logger.debug("生成最新编制--开始");

}

ErpCommon.getService(OrginazitionNewService.class).updateNewestEndM();

if (logger.isDebugEnabled()) {

logger.debug("生成最新编制--结束");

}

}

System.out.println("-------执行生成一份最新的编制到一个表里end--------------");

RedisShardedPoolUtil.del(lockName);

System.out.println("释放" + lockName + ",ThreadName:" + Thread.currentThread());

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值