1、Timer 实现定时任务
1.1、JDK1.3 开始推出定时任务实现工具。
1.2、API

执行代码
public static void main(String[] args) throws ParseException {
Timer timer = new Timer();
String str="2024-06-10 23:24:00";
Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(str);
timer.schedule(new TimerTask() {
@Override
public void run() {
System.out.println("定时任务执行");
System.out.println("定时任务执行时间--》"+new Date());
}
},date);
}
public static void main(String[] args) throws ParseException {
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
System.out.println("定时任务执行");
System.out.println("定时任务执行时间--》"+new Date());
}
},0,2000);
}
2、使用spring进行整合

//pom文件
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
spring:
task:
execution:
thread-name-prefix: task_
shutdown:
await-termination: false
await-termination-period: 10s
scheduling:
pool:
size: 10
@Scheduled(cron = "0/3 * * * * ? ")
public void test1() {
System.out.println("定时任务执行test1");
System.out.println("定时任务执行时间--》"+new Date());
}
@Scheduled(cron = "0/3 * * * * ? ")
public void test2() {
System.out.println("定时任务执行test2");
System.out.println("定时任务执行时间--》"+new Date());
}















![[大模型]GLM-4-9b-Chat 接入 LangChain](https://img-blog.csdnimg.cn/direct/973dcde342ac4d39a10abf6eb8f604b5.png#pic_center)

![BUUCTF---web---[GYCTF2020]Blacklist](https://img-blog.csdnimg.cn/direct/8909f8f48e3845399905b763efb91b0c.png)

