package org.demo.scheduletest.service;
import com.rabbitmq.client.Channel;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
@Data
@Slf4j
public class DataSyncTask implements Runnable {
private String name;
private Channel channel;
private long deliveryTag;
public DataSyncTask(String name, Channel channel, long deliveryTag) {
this.name = name;
this.channel = channel;
this.deliveryTag = deliveryTag;
}
/**
* When an object implementing interface <code>Runnable</code> is used
* to create a thread, starting the thread causes the object's
* <code>run</code> method to be called in that separately executing
* thread.
* <p>
* The general contract of the method <code>run</code> is that it may
* take any action whatsoever.
*
* @see Thread#run()
*/
@Override
public void run() {
log.info("[DataSyncTask] run task start, name = {}", name);
try {
Thread.sleep(30000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
try {
channel.basicAck(deliveryTag, true);
log.info("[DataSyncTask] run task end, name = {}", name);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
InitTask,服务启动执行Task管理器
package org.demo.scheduletest.service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
/**
* @author zhe.xiao
* @version 1.0
* @since 2025/1/9 上午11:38
*/
@Slf4j
@Component
public class InitTask implements ApplicationRunner {
/**
* Callback used to run the bean.
*
* @param args incoming application arguments
* @throws Exception on error
*/
@Override
public void run(ApplicationArguments args) throws Exception {
DataSyncTaskManager.getManager().runTaskDaemon();
}
}
命令模式(Command Pattern) 命令模式(Command Pattern)命令设计模式命令设计模式结构图命令设计模式涉及的角色 talk is cheap, show you my code总结 命令模式(Command Pattern)
命令模式&…
传参和返参的效果图如下:
传参: 返参: 代码实现:
1、最外层类
/*** 外层DATA类*/
XmlRootElement(name "DATA")
public class PointsXmlData {private int rltFlag;private int failType;private String failMemo;p…