quartz框架没问题。

流程:

sping-quartz配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-4.0.xsd "> <context:annotation-config/> <task:annotation-driven/> <!-- 业务对象 -->
<bean id="testJobTask" class="com.sunyard.quartz.TestQuartzTask" />
<!-- 自动扫描包 -->
<context:component-scan base-package="com.sunyard.quartz.*" /> <!-- 定时任务start --> <!-- 调度业务 -->
<bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="testJobTask" />
<property name="targetMethod" value="execute" />
</bean> <!-- 增加调用的触发器,触发时间 并注入到调度工厂-->
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="jobDetail" />
<property name="cronExpression" value="0/10 * * * * ? *" />
</bean> <!-- 设置调度工厂 注入触发器-->
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="cronTrigger" />
</list>
</property>
</bean> <!-- 定时任务end --> </beans>

之后在web.xml中

 <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring-mybatis.xml,
classpath:spring-quartz.xml
</param-value>
</context-param>

测试

/**
* 定时任务--打印测试定时任务是否成功
* @author wang
*
*/
public class TestQuartzTask{
public void execute() {
System.out.println("定时任务已启动!");
}
}

之后发现启动之后输出两行,即任务启动两次。

最终解决:

<Host appBase="" autoDeploy="true" name="localhost" unpackWARs="true">

将appBase置空即可

quartz定时定时任务执行两次的更多相关文章

  1. spring定时任务执行两次的原因与解决方法

    spring定时任务,本地执行一次,放到服务器上后,每次执行时会执行两次,原因及解决办法. http://blog.csdn.net/yaobengen/article/details/7031266 ...

  2. spring学习笔记--quartz和定时任务执行

    前言: 最近要写一个定时任务, 用于同步数据. 以往这种涉及数据库操作的定时脚本, 都会采用python+crontab的方式来实现. 这次画风大转, 决定试试用spring+quartz来实现一下. ...

  3. 关于Spring中,定时任务执行两次的解决办法

    原因:如果spring-quartz.xml文件,在Spring的配置文件spring-config.xml中被加载,那么定时任务会被Spring和SpringMVC扫描两次,所以会被执行两次. 解决 ...

  4. spring定时任务执行两次

    最近用Spring的quartz定时器的时候,发现到时间后,任务总是重复执行两次,在tomcat或jboss下都如此. 打印出他们的hashcode,发现是不一样的,也就是说,在web容器启动的时候, ...

  5. quartz 应用到 spring定时任务 执行两次

    https://my.oschina.net/superkangning/blog/467487

  6. spring定时任务执行两次 项目重复初始化 项目启动两次

    tomcat/config/server.xml中Host标签Context节点的问题 项目里quartz定时器总是被执行2次,通过打印发现原来项目被加载了两次,所以项目下的Listener被重复加载 ...

  7. spring 定时任务执行两次解决办法

    在web.xml中同时配置了ContextLoaderListener和DispatcherServlet?假如真是这样的话,需要删掉一个配置,因为你相当于配置了两个spring容器,两个容器分别都执 ...

  8. sprint定时任务执行两次

    我这里遇到的是tomcat问题,把appBase设置为空 <Host name="localhost" appBase="" unpackWARs=&qu ...

  9. Spring整合Quartz定时任务执行2次,Spring定时任务执行2次

    Spring整合Quartz定时任务执行2次,Spring定时任务执行2次 >>>>>>>>>>>>>>>&g ...

随机推荐

  1. Django中出现no such table: django_session

    这个错误跟Session的机制有关, 既然要从Web服务器端来记录用户信息, 那么一定要有存放用户session id对应信息的地方才行. 所以,我们需要创建django_session表. Djan ...

  2. mysql 手动把字段设置为null

    在根据经纬度计算距离的时候,发现有的视频点距离我当前位置的距离计算出来的为0,有的距离计算出来是几千公里,仔细看下数据库,发现了问题所在 计算出来几千公里的视屏点的经纬度是空不是null,然后我们手动 ...

  3. hdu 2583 How far away ? 离线算法 带权求最近距离

    How far away ? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  4. CodeForces - 706C Hard problem(dp+字符串)

    题意:有n个字符串,只能将其逆转,不能交换位置,且已知逆转某字符串需要消耗的能量,问将这n个字符串按字典序从小到大排序所需消耗的最少能量. 分析:每个字符串要么逆转,要么不逆转,相邻两个字符串进行比较 ...

  5. 【转】Java线程面试题 Top 50(转)

    不管你是新程序员还是老手,你一定在面试中遇到过有关线程的问题.Java语言一个重要的特点就是内置了对并发的支持,让Java大受企业和程序员的欢迎.大多数待遇丰厚的Java开发职位都要求开发者精通多线程 ...

  6. tortoiseGit 的简单使用说明

    拉取仓库到本地 参考 下面几张图片,把仓库拉取到本地. 本地修改并推送 进入文件夹后,按照 下面几张图片切换到本地的开发分支 当修改完成之后,按照 下面几张图片 的方法把修改推送到远程仓库的开发分支. ...

  7. 18个python的高效编程技巧

    01 交换变量 >>>a=3 >>>b=6 这个情况如果要交换变量在c++中,肯定需要一个空变量.但是python不需要,只需一行,大家看清楚了 >>& ...

  8. Flink并行度

    并行执行 本节介绍如何在Flink中配置程序的并行执行.FLink程序由多个任务(转换/操作符.数据源和sinks)组成.任务被分成多个并行实例来执行,每个并行实例处理任务的输入数据的子集.任务的并行 ...

  9. [CISCN2019 总决赛 Day1 Web4]Laravel1

    0x00 知识点 这个题核心就是找POP链,看了一下网上的WP,难顶啊.. 先贴上思路和poc,之后等熟练了再来做吧 https://glotozz.github.io/2019/11/05/buuc ...

  10. Hibernate(二)——一对多查询

    1. 前言 本章节我们讨论Hibernate一对多查询的处理. 在上一章节中(Hibernate(一)——入门),我们探讨了Hibernate执行最基本的增删改查操作.现在我们将情况复杂化:加入我们在 ...