我尝试使用Quartz来安排在Glassfish上运行的网络应用中的工作。我正在使用RAMJobStore。问题在于,有时候,即使是在过去或将来安排的,也没有执行被安排的工作。作业量非常低,在调度程序上始终安排总计不到20个作业,并且保证最多同时运行1个作业,所以我认为线程数不是问题,我可以将其设置为threadCount 1,它仍然可以工作。在销毁servlet之前,调度程序也没有被关闭。那么一些工作没有被运行的原因是什么呢?
StartupServlet
public void init()
{
try
{
scheduler = StdSchedulerFactory.getDefaultScheduler();
scheduler.start();
loadJobs();
}
catch (SchedulerException se)
{
se.printStackTrace();
}
}
@Override
public void destroy()
{
try
{
scheduler.shutdown();
}
catch (SchedulerException se)
{
se.printStackTrace();
}
}
安排作业
JobDetail job = JobBuilder.newJob(ScheduledTransactionJob.class)
.withIdentity(transaction.getId())
.build();
Trigger trigger = TriggerBuilder.newTrigger()
.withIdentity(transaction.getId())
.startAt(date)
.build();
try
{
scheduler.scheduleJob(job, trigger);
dateFormat = new SimpleDateFormat("dd MMM yyyy, HH:mm:ss");
String recurringTransactionTime = dateFormat.format(date);
logger.info("Scheduled job for " + recurringTransactionTime);
}
catch (SchedulerException se)
{
se.printStackTrace();
}
quartz.properties
#============================================================================
# Configure Main Scheduler Properties
#============================================================================
org.quartz.scheduler.skipUpdateCheck = true
org.quartz.scheduler.instanceName = AppScheduler
org.quartz.scheduler.instanceId = AUTO
#============================================================================
# Configure ThreadPool
#============================================================================
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 25
org.quartz.threadPool.threadPriority = 10
#============================================================================
# Configure JobStore
#============================================================================
org.quartz.jobStore.misfireThreshold = 60000
org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
答案 0 :(得分:0)
似乎现在正在工作。避风港遇到了更多问题。可能是配置问题,因为我在/src/main/resources
中移动了配置文件。
还尝试打开登录以帮助进行调试:
log4j.logger.com.gargoylesoftware.htmlunit=DEBUG
我们还添加了一个JobTriggerListener来帮助处理日志:
private static class JobTriggerListener implements TriggerListener
{
private String name;
public JobTriggerListener(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void triggerComplete(Trigger trigger, JobExecutionContext context,
Trigger.CompletedExecutionInstruction triggerInstructionCode)
{
}
public void triggerFired(Trigger trigger, JobExecutionContext context)
{
}
public void triggerMisfired(Trigger trigger)
{
logger.warn("Trigger misfired for trigger: " + trigger.getKey());
try
{
logger.info("Available threads: " + scheduler.getCurrentlyExecutingJobs());
}
catch (SchedulerException ex)
{
logger.error("Could not get currently executing jobs.", ex);
}
}
public boolean vetoJobExecution(Trigger trigger, JobExecutionContext context)
{
return false;
}
}