我的漫漫程序之旅

专注于JavaWeb开发
随笔 - 39, 文章 - 310, 评论 - 411, 引用 - 0
数据加载中……

Quartz优先级的使用

建三个Job类:
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

public class JobTest1 implements Job
{

    
public void execute(JobExecutionContext jobexecutioncontext)
            
throws JobExecutionException
    
{
        System.out.println(
"JobTest1");
    }


}

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

public class JobTest2 implements Job
{

    
public void execute(JobExecutionContext jobexecutioncontext)
            
throws JobExecutionException
    
{
        System.out.println(
"JobTest2");
    }


}
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

public class JobTest3 implements Job
{

    
public void execute(JobExecutionContext jobexecutioncontext)
            
throws JobExecutionException
    
{
        System.out.println(
"JobTest3");
    }


}


比较简单,上面三个类就不多说了.
测试类:

import java.util.Date;

import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleTrigger;
import org.quartz.Trigger;
import org.quartz.impl.StdSchedulerFactory;

public class PriorityTest
{
    
public static void main(String[] args) throws Exception
    
{
        SchedulerFactory sf 
= new StdSchedulerFactory();
        Scheduler scheduler 
= sf.getScheduler();

        JobDetail job1 
= new JobDetail();
        job1.setName(
"jobDetail1");
        job1.setGroup(
"a");
        job1.setJobClass(JobTest1.
class);

        JobDetail job2 
= new JobDetail();
        job2.setName(
"jobDetail2");
        job2.setGroup(
"b");
        job2.setJobClass(JobTest2.
class);

        JobDetail job3 
= new JobDetail();
        job3.setName(
"jobDetail3");
        job3.setGroup(
"c");
        job3.setJobClass(JobTest3.
class);

        Trigger trigger1 
= new SimpleTrigger();
        trigger1.setName(
"trigger1");
        trigger1.setStartTime(
new Date());
        
//优先级默认是5
        trigger1.setPriority(Trigger.DEFAULT_PRIORITY);
        
        Trigger trigger2 
= new SimpleTrigger();
        trigger2.setName(
"trigger2");
        trigger2.setStartTime(
new Date());
        trigger2.setPriority(
100);
        
        Trigger trigger3 
= new SimpleTrigger();
        trigger3.setName(
"trigger3");
        trigger3.setStartTime(
new Date());
        trigger3.setPriority(
15);
        
        
        scheduler.scheduleJob(job1, trigger1);
        scheduler.scheduleJob(job2, trigger2);
        scheduler.scheduleJob(job3, trigger3);

        scheduler.start();
    }


}

输出:
JobTest2
JobTest3
JobTest1
由此我们可以看出优先级决定于整形数值的大小.
数值越大优先级越高.

posted on 2008-05-08 16:36 々上善若水々 阅读(5651) 评论(0)  编辑  收藏 所属分类: opensource


只有注册用户登录后才能发表评论。


网站导航: