1. sn
This commit is contained in:
@@ -9,15 +9,15 @@ import java.util.Map;
|
||||
|
||||
public class Management {
|
||||
private static final List<Timer> timerJobList = new ArrayList<>();
|
||||
private static final List<CronJob> cronJobs = new ArrayList<>();
|
||||
|
||||
public static void start() {
|
||||
for (Map.Entry<String, Message> value : FileBuild.getMessageHashMap().entrySet()) {
|
||||
Message message = value.getValue();
|
||||
if (!message.enable) continue;
|
||||
if (message.cronJob) {
|
||||
startCronJob(message);
|
||||
|
||||
|
||||
if (message.exactTime) {
|
||||
CronJob cronJob = new CronJob(message);
|
||||
cronJobs.add(cronJob);
|
||||
} else {
|
||||
Timer job = new Timer(message);
|
||||
timerJobList.add(job);
|
||||
@@ -25,37 +25,12 @@ public class Management {
|
||||
}
|
||||
}
|
||||
|
||||
public static void startCronJob(Message message) {
|
||||
try {
|
||||
CronJob cronJob = new CronJob(message);
|
||||
JobDetail job = JobBuilder.newJob(cronJob.getClass())
|
||||
.withIdentity(message.key, message.key).build();
|
||||
Trigger trigger = TriggerBuilder.newTrigger()
|
||||
.withIdentity(message.key, message.key)
|
||||
.withSchedule(CronScheduleBuilder.cronSchedule(message.cronJobString))
|
||||
//.withSchedule(CronScheduleBuilder.cronSchedule("0/5 * * * * ?"))
|
||||
.build();
|
||||
Scheduler scheduler = new StdSchedulerFactory().getScheduler();
|
||||
scheduler.start();
|
||||
scheduler.scheduleJob(job, trigger);
|
||||
jobList.add(scheduler);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void end() {
|
||||
for (Timer job : timerJobList) {
|
||||
job.disable = true;
|
||||
}
|
||||
for (Scheduler scheduler : jobList) {
|
||||
try {
|
||||
scheduler.shutdown();
|
||||
} catch (SchedulerException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
for (CronJob cronJob : cronJobs) {
|
||||
cronJob.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user