美文网首页
java maven quartz exampe 实战攻略

java maven quartz exampe 实战攻略

作者: 零点145 | 来源:发表于2019-06-13 14:20 被阅读0次

    pom.xml

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

      <modelVersion>4.0.0</modelVersion>

      <groupId>cn.net.simpv.task</groupId>

      <artifactId>cn.net.simpv.task1</artifactId>

      <version>1.0-SNAPSHOT</version>

      <packaging>jar</packaging>

      <name>cn.net.simpv.task1</name>

      <url>http://maven.apache.org</url>

      <properties>

        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <slf4j.version>1.7.6</slf4j.version>

    <logback.version>1.1.1</logback.version>

    <spring.version>4.0.2.RELEASE</spring.version>

    <maven.compiler.source>1.7</maven.compiler.source>

    <maven.compiler.target>1.7</maven.compiler.target>

      </properties>

      <build>

    <plugins>

    <plugin>

    <groupId>org.eclipse.jetty</groupId>

    <artifactId>jetty-maven-plugin</artifactId>

    <version>9.1.4.v20140401</version>

    <configuration> 

                  <encoding>UTF-8</encoding> 

                </configuration>

    </plugin>

    <plugin>

    <groupId>org.apache.maven.plugins</groupId>

    <artifactId>maven-source-plugin</artifactId>

    <executions>

    <execution>

    <id>attach-sources</id>

    <goals>

    <goal>jar</goal>

    </goals>

    </execution>

    </executions>

    <configuration> 

                  <encoding>UTF-8</encoding> 

                </configuration> 

    </plugin>

    </plugins>

    </build>

      <dependencies>

      <dependency>

    <groupId>org.springframework</groupId>

    <artifactId>spring-test</artifactId>

    <version>${spring.version}</version>

    <scope>test</scope>

    </dependency>

        <dependency>

        <groupId>junit</groupId>

        <artifactId>junit</artifactId>

        <version>3.8.1</version>

        <scope>test</scope>

        </dependency>

    <dependency>

    <groupId>org.opensymphony.quartz</groupId>

    <artifactId>quartz-all</artifactId>

    <version>1.6.1</version>

    </dependency>

    <dependency>

    <groupId>commons-collections</groupId>

    <artifactId>commons-collections</artifactId>

    <version>3.2.1</version>

    </dependency>

      </dependencies>

    </project>

    SimpleJob.java

    package cn.net.simpv.task;

    import java.util.Date;

    import org.quartz.Job;

    import org.quartz.JobExecutionContext;

    import org.quartz.JobExecutionException;

    public  class SimpleJob implements Job {

        public void execute(JobExecutionContext jobCtx)throws JobExecutionException

        {

          System.out.println(jobCtx.getTrigger().getClass().getName()+"triggered time is:"+new Date());

        }

    }

    App.java

    package cn.net.simpv.task;

    import java.util.Date;

    import org.quartz.JobDetail;

    import org.quartz.Scheduler;

    import org.quartz.SchedulerFactory;

    import org.quartz.SimpleTrigger;

    import org.quartz.impl.StdSchedulerFactory;

    /**

    * Hello world!

    *

    */

    public class App

    {

        public static void main( String[] args )

        {

            System.out.println("Hello World!");

            try

            {

            JobDetail jobdetail = new JobDetail("job1_1","jgroup1",SimpleJob.class);

            SimpleTrigger  simpleTrigger=new SimpleTrigger("trigger1","tgroup1");

            simpleTrigger.setStartTime(new Date());

            simpleTrigger.setRepeatInterval(1000);

            simpleTrigger.setRepeatCount(1);

            SchedulerFactory schedulerFactory=new StdSchedulerFactory();

            Scheduler scheduler=schedulerFactory.getScheduler();

            scheduler.scheduleJob(jobdetail,simpleTrigger);

            scheduler.start();

            }catch(Exception ex)

            {

            ex.printStackTrace();

            }

        }

    }

    最后给你们推荐一个群,如果你还想提升自己,

    欢迎加入Java技术交流群:659270626

    本群提供免费的学习指导 提供Spring源码、MyBatis、Netty、Redis,Kafka、Mysql、Zookeeper、Tomcat、Docker、Dubbo、Nginx、分布式、高并发、性能调优、等架构技术架构资料 以及免费的解答

    不懂的问题都可以在本群提出来 之后还会有职业生涯规划以及面试指导 

    相关文章

      网友评论

          本文标题:java maven quartz exampe 实战攻略

          本文链接:https://www.haomeiwen.com/subject/ciqsfctx.html