• quartz mysql , shiro logout


    
    
    @Named
    public class SampleJob implements Job {
    
        @Inject
        private AService aService;
    
       @Override
        public void execute(JobExecutionContext context)
            throws JobExecutionException {
    
           //Do injection with spring
            SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
            aService.doIt();
           }
    }

    http://stackoverflow.com/questions/4258313/how-to-use-autowired-in-a-quartz-job
    
    
    ApplicationContext springContext = 
        WebApplicationContextUtils.getWebApplicationContext(
            ContextLoaderListener.getCurrentWebApplicationContext().getServletContext()
        );
    Bean bean = (Bean) springContext.getBean("beanName");
    bean.method();
    package com.yingcao.springdatajpa.quartz;
    
    import java.util.List;
    
    import javax.servlet.ServletContextEvent;
    import javax.servlet.ServletContextListener;
    
    import org.quartz.Scheduler;
    import org.quartz.SchedulerFactory;
    import org.quartz.Trigger;
    import org.quartz.TriggerKey;
    import org.quartz.impl.StdSchedulerFactory;
    
    public class ScheduleStartListener implements ServletContextListener {
        public void contextDestroyed(ServletContextEvent sce) {
    
        }
    
        public void contextInitialized(ServletContextEvent sce) {
            try {
                recovery();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
        public void recovery() {
    
            Scheduler scheduler = null;
            try {
    
                SchedulerFactory schedulerFactory = new StdSchedulerFactory();
                scheduler = schedulerFactory.getScheduler();// 可以通过SchedulerFactory创建一个Scheduler实例
                List<String> triggerGroups = scheduler.getTriggerGroupNames();// 获取调度器中所有的触发器组
                System.out.println("调度器中所有的触发器组 size():" + triggerGroups.size());
                if (triggerGroups != null && triggerGroups.size() != 0)// 重新恢复在triggerGroups组中所有的触发器
                {
                    for(int i = 0; i <triggerGroups.size();i++)
                    {
                        TriggerKey triggerKey = TriggerKey.triggerKey(
                                triggerGroups.get(i), triggerGroups.get(i));
                        System.out.println("triggerKey:" + triggerKey);
    
                        Trigger tg = scheduler.getTrigger(triggerKey);// 获取trigger
                        System.out.println(triggerKey + " -> 执行时间 :"
                                + tg.getNextFireTime());
    
                        scheduler.rescheduleJob(triggerKey, tg);// 按新的trigger重新设置job执行 }
                    }
    
                    scheduler.start();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }


    package com.yingcao.springdatajpa.quartz;

    import static org.quartz.JobBuilder.newJob;
    import static org.quartz.TriggerBuilder.newTrigger;

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

    public class QuartzTest {
        
        public void run(String date, int id) throws Exception {

            SchedulerFactory schedulerFactory = new StdSchedulerFactory();
            Scheduler scheduler = schedulerFactory.getScheduler();// 可以通过SchedulerFactory创建一个Scheduler实例
            // 设置工作详情
            JobDetail job = newJob(JobTest.class).withIdentity("job_" + id,
                    "test" + id) // (String name, String
                                    // group)把触发器在集群节点实例命名的组只是为了区分(伐木)从什么地方定问调度重新执行此作业,如果它是正在进行时调度下去...
                                    // .requestRecovery()
                    .build();

            job.getJobDataMap().put("testId", id); // 设置存储参数(不需要可删除)

            SimpleTrigger trigger = (SimpleTrigger) newTrigger().withIdentity(
                    "overdue" + id, "overdue" + id)// withIdentity("trigger",
                                                    // "group") .startAt(startDate)
                    .build();

            scheduler.scheduleJob(job, trigger);
            scheduler.start();
            System.out.println("------- Start Scheduler ----------------");
        }

        public static void main(String[] args) throws Exception {
            QuartzTest quartzOverdue = new QuartzTest();
            quartzOverdue.run("2014-07-02 00:30:00", 666);// 666,随便的吉祥数字
        }
    }


    http://blog.csdn.net/Uhzgnaw/article/details/46358333

    org.quartz.scheduler.instanceName = DefaultQuartzScheduler
    org.quartz.scheduler.rmi.export = false
    org.quartz.scheduler.rmi.proxy = false
    org.quartz.scheduler.wrapJobExecutionInUserTransaction = false
     
    org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
    org.quartz.threadPool.threadCount = 10
    org.quartz.threadPool.threadPriority = 5
    org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true
     
    org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
    org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate  
    org.quartz.jobStore.useProperties = false
    org.quartz.jobStore.tablePrefix = QRTZ_  
    org.quartz.jobStore.isClustered = false  
    # Configure Datasources 
    #============================================================================ 
    org.quartz.jobStore.dataSource = myDS
    org.quartz.dataSource.myDS.driver = com.mysql.jdbc.Driver 
    org.quartz.dataSource.myDS.URL = jdbc:mysql://localhost:3306/quartz1x?useUnicode=true&characterEncoding=utf8 
    org.quartz.dataSource.myDS.user = root 
    org.quartz.dataSource.myDS.password =111111
    org.quartz.dataSource.myDS.maxConnections = 10 
    <bean id="scheduler"
        class="org.springframework.scheduling.quartz.SchedulerFactoryBean"
        lazy-init="false">
        <property name="configLocation" value="classpath:quartz.properties" />
    </bean>
    <bean id="logout" class="org.apache.shiro.web.filter.authc.LogoutFilter">
        <property name="redirectUrl" value="/loginform" />
    </bean> 
    /logout = logout
  • 相关阅读:
    GO学习之 为什么选择GO
    Flask学习之 Jinja2模板引擎
    排序算法之归并排序的python实现
    排序算法之快速排序的python实现
    排序算法之希尔排序的python实现
    排序算法之插入排序的python实现
    排序算法之选择排序的python实现
    Android 中正则表达式工具类
    java之从字符串比较到==和equals方法区别
    Android Studio酷炫插件(一)——自动化快速实现Parcelable接口序列化
  • 原文地址:https://www.cnblogs.com/zouhao510/p/5313548.html
Copyright © 2020-2023  润新知