gpt4 book ai didi

java - Quartz 调度程序无法获取 JNDI DB 资源但无论如何都会启动

转载 作者:行者123 更新时间:2023-11-28 21:53:26 25 4
gpt4 key购买 nike

我正在使用 QuartzInitializerListener 在我的 tomcat 8 中初始化 Quartz 调度器。

当 Quartz 无法连接到我的数据库(JNDI 资源)时:

15-Dec-2014 09:26:58.201 INFO [http-nio-8080-exec-10] org.apache.catalina.startup.HostConfig.deployDirectory 部署 Web 应用程序目录/home/.../org.quartz.SchedulerConfigException:作业恢复期间发生故障。 [参见嵌套异常:org.quartz.JobPersistenceException:无法从数据源“DBConnectionPool”获取数据库连接:java.sql.SQLException:无法通过 JNDI url“java:comp/env/jdbc/DBConnectionPool”java.sql 检索数据源.SQLException:无法创建 PoolableConnectionFactory(通信链接失败

它无论如何都会根据 quartz.propertiens 启动。它没有做任何事情......但如果发生这种情况,我希望 Quartz 停止!

我怎样才能做到这一点?

问候塞巴斯蒂安

最佳答案

您可以像这样使用您的自定义类,而不是使用 quartzlistner。将其用作满足您要求的骨架

@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
}

}

关于java - Quartz 调度程序无法获取 JNDI DB 资源但无论如何都会启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27480324/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com