手动创建并启动定时器方法:
/**
* <创建定时器>
* <创建定时器执行指定类并确认是否立刻执行>
* @param timer 定时器间隔
* @param jobClass 任务类
* @param bool 是否立刻执行
* @param repeatCount 执行的次数,-1代表一直执行
* @return 返回创建的定时器
* @see [类、类#方法、类#成员]
*/
public static Scheduler createScheduler(long timer, Class<?> jobClass, boolean bool, int repeatCount)
{
try
{
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
JobDetail jobDetail = new JobDetail(getID("Job"), Scheduler.DEFAULT_GROUP, jobClass);
Trigger trigger = new SimpleTrigger(getID("Trigger"), Scheduler.DEFAULT_GROUP, repeatCount, timer);
scheduler.scheduleJob(jobDetail, trigger);
if (bool)
{
scheduler.start();
}
return scheduler;
}
catch (SchedulerException e)
{
logger.error("Global Exception Is ", e);
}
return null;
}