Quartz scheduler failed to get JNDI DB resource but still starts

I am using QuartzInitializerListener to start Quartz scheduler in my tomcat 8.

When Quartz cannot get a connection to my database (JNDI resource):

15-Dec-2014 09:26:58.201 INFO [http-nio-8080-exec-10] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /home/.../ org.quartz.SchedulerConfigException: Failure occured during job recovery. [See nested exception: org.quartz.JobPersistenceException: Failed to obtain DB connection from data source 'DBConnectionPool': java.sql.SQLException: Could not retrieve datasource via JNDI url 'java:comp/env/jdbc/DBConnectionPool' java.sql.SQLException: Cannot create PoolableConnectionFactory (Communications link failure

still starts according to quartz.propertiesn. It doesn't do anything ... but I want Quartz to stop if it does!

How can I achieve this?

Sebastian relationship

+3


source to share


1 answer


Instead of using quartzlistner, you can use your own class like this. Use it as a skeleton for your requirement



@WebServlet(value="/QuartzTest",loadOnStartup=1)
public class QuartzInit extends HttpServlet {
    private static final long serialVersionUID = 1L;
    public static int count=0;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public QuartzInit() {
        super();

        // TODO Auto-generated constructor stub
        try {

       System.out.println("TRying to start Quartz");

            JobDetail job = JobBuilder.newJob(AppCheckerJob.class)
                .withIdentity("AppCrawlerJob", "InfraStatus_Group").build();

            JobDetail job_email = JobBuilder.newJob(EmailJob.class)
                    .withIdentity("AppCrawlerEmailJob", "InfraStatus_Group").build();


            Trigger trigger = TriggerBuilder
                .newTrigger()
                .withIdentity("AppCrawlerJobTRigger", "InfraStatus_Group")
                .withSchedule(        


                                CronScheduleBuilder.cronSchedule("0 /15 * * * ?")


                ).build();

            Trigger trigger_email = TriggerBuilder
                    .newTrigger()
                    .withIdentity("AppCrawlerEmailJobTRigger", "InfraStatus_Group")
                    .withSchedule(        


                            CronScheduleBuilder.dailyAtHourAndMinute(13,16)
                    ).build();


            // schedule it
            Scheduler scheduler = new StdSchedulerFactory().getScheduler();

            scheduler.start();

            //if (sched.checkExists(job.getKey())) {sched.rescheduleJob(trigger.getKey(), trigger); } else {sched.scheduleJob(job, trigger); } 

            if(scheduler.checkExists(job.getKey())){
                System.out.println("deleting old job netry");
                scheduler.deleteJob(job.getKey());
                //scheduler.rescheduleJob(trigger.getKey(), trigger);
            }
            if(scheduler.checkExists(job_email.getKey())){
                System.out.println("deleting old email job netry");
                scheduler.deleteJob(job_email.getKey());
                //scheduler.rescheduleJob(trigger.getKey(), trigger);
            }



            scheduler.scheduleJob(job, trigger);            
            scheduler.scheduleJob(job_email, trigger_email);




        } catch (Exception se) {
            se.printStackTrace();
           throw new RuntimeException("Error while initializing quartz!!!");
        }

    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }

}

      

0


source







All Articles