首页 > 其他分享 >任务

任务

时间:2022-12-20 12:23:25浏览次数:27  
标签:qq void simpleMailMessage 任务 mail com public

1、异步任务
开启

@SpringBootApplication
@EnableAsync
public class Demo14Application {

    public static void main(String[] args) {
        SpringApplication.run(Demo14Application.class, args);
    }

}

使用

    @Async
    public void hello(){
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

2、邮件任务
依赖

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>

配置

[email protected]
spring.mail.password=seamfpgsfjthdhgc
spring.mail.host=smtp.qq.com
#开启加密验证
spring.mail.properties.mail.smtp.ssl.enable=true

使用

@Test
    void contextLoads() {
        //发送一个简单的邮件
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setSubject("Yan");
        simpleMailMessage.setText("hello Yan");
        simpleMailMessage.setFrom("[email protected]");
        simpleMailMessage.setTo("[email protected]");
        mailSender.send(simpleMailMessage);
    }
    @Test
    void contextLoads1() throws MessagingException {
        //发送一个复杂的邮件
        MimeMessage mimeMessage = mailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,true);
        helper.setSubject("Yan");
        helper.setText("hello Yan");
        helper.setFrom("[email protected]");
        helper.setTo("[email protected]");
        helper.addAttachment("20201022160116.png", new File("C:\\Users\\Alex Mercer\\Desktop\\20201022160116.png"));
        mailSender.send(mimeMessage);
    }

3、定时任务
TaskExecutor
TaskScheduler
开启

@SpringBootApplication
@EnableScheduling
public class Demo14Application {

    public static void main(String[] args) {
        SpringApplication.run(Demo14Application.class, args);
    }

}

使用

@Service
public class HelloService {
    @Scheduled(cron = "0/2 * * * * ?")
    public void hello(){
        System.out.println("hello");
    }
}

标签:qq,void,simpleMailMessage,任务,mail,com,public
From: https://www.cnblogs.com/yanshiheng/p/16993906.html

相关文章

  • 让Linux任务在后台可靠运行的几种方法
     我们经常会碰到这样的问题,用telnet/ssh登录了远程的Linux服务器,运行了一些耗时较长的任务,结果却由于网络的不稳定导致任务中途失败。如何让命令提交后不受本地关闭终......
  • 事件队列(宏任务、微任务)
    概念因为js是单线程执行,为了防止某个进程堵塞将后面的代码堵死,所以设置了一套规则。首先,js会将同步的代码放到一起,然后压入执行栈,然后将异步代码放入异步队列。异步队列又......
  • 钉钉待办任务的创建
    publicstaticvoidmain(String[]args){ //----------------------获取accesstoken------ Stringappkey="dingythexhoab0d1nkq3"; Stringappsecret="AEySJvyiaKQ3......
  • FreeRTOS学习笔记——任务壮态或信息查询与任务运行时间统计
    说明:这个方面用的也是比较多的,查看当前任务的运行状态,切记由于消耗内存,只有在debug的时候使用,正式软件直接关闭这里有一位网友写的特别的好,引用参考一下,对此表示感......
  • windwos10任务栏居中
    如下操作新建一个文件夹如图然后出现这个重右往左一直拖然后拉出来就行了如图拖不动或者没有的把这个关了-锁定任务栏文字如何隐藏?在这个文字旁边右......
  • spring boot —— 整合Scheduling定时任务
    Spring3.0后提供SpringTask实现任务调度,支持按日历调度,相比Quartz功能稍简单,但是在开发基本够用,支持注解编程方式。使用启用在springboot启动类上添加注解:@EnableSch......
  • Spring的两种任务调度Scheduled和Async
    Spring提供了两种后台任务的方法,分别是:调度任务,@Schedule异步任务,@Async当然,使用这两个是有条件的,需要在spring应用的上下文中声明​​​<task:annotation-driven/>​​​......
  • python多线程实现爬虫任务
    python语言对于网络爬虫来说是非常重要的,大多数互联网公司都热衷于python语言编写爬虫。那么如果大批量做爬虫工作,如何才能快速的爬取数据,这就需要多线程多任务操作才能快速......
  • 07 预训练语言模型的下游任务改造简介(如何使用词向量)
    Word2Vec--》是一个神经网络语言模型,其次他的主要任务是做(生成词向量,Q)![image-20220614194418918](../../Library/ApplicationSupport/typora-user-images/image-2022061......
  • TIDB-DM数据迁移第二部(创建同步任务)
    文档:https://docs.pingcap.com/zh/tidb/stable/quick-start-create-source实验环境源(MySQL):10.255.8.122:3306目标(TiDB):172.16.1.10:3306全量加增量模式,忽略test......