java Quartz调度程序在应用程序隐藏时不执行
我编写了一个java应用程序,它应该自动运行。我在这里使用了石英调度器。在我的应用程序中,它从不在关闭UI s时关闭。它可以通过关闭电脑或从系统托盘退出来关闭
当应用程序在后台运行时,我设置了自动启动调度程序的精确时间。但它不起作用
以下是我遵循的步骤
这是我的主课
备份系统v01。java
public class BackupSystemv01
{
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
new BackupSystemv01();
boolean isDisplay = false;
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex)
{
JOptionPane.showMessageDialog(null, "Cannot set a look and feel . ");
}
if (args.length == 0)
{
isDisplay = true;
} else
{
isDisplay = Boolean.parseBoolean(args[0]);
}
LocationOperator locationOperator = new LocationOperator();
SaveFileLocations lastRecord = locationOperator.getLastRecord();
BackUpModeOperator backUpModeOperator = new BackUpModeOperator();
backUpModeOperator.createBackUpMode();
BackUpMode backUpMode = backUpModeOperator.getBackUpMode(1);
Calendar c = Calendar.getInstance();
c.setTimeInMillis(System.currentTimeMillis());
int day_of_week = c.get(Calendar.DAY_OF_WEEK);
int HOUR = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
int MINUTE = Calendar.getInstance().get(Calendar.MINUTE);
AutoBackUp autoBackUp = new AutoBackUp();
if (backUpMode != null)
{
if (backUpMode.isMode() == true)
{
String day = backUpMode.getDay();
String[] split = day.split(",");
for (String split1 : split)
{
Integer dt = Integer.parseInt(split1);
if (dt == day_of_week)
{
if (backUpMode.getBackUpTime() != null)
{
Time backUpTime = backUpMode.getBackUpTime();
String toString = backUpTime.toString();
String[] split2 = toString.split(":");
Integer hour = 0;
Integer minute = 0;
for (int j = 0; j < split2.length; j++)
{
hour = Integer.parseInt(split2[0]);
minute = Integer.parseInt(split2[1]);
}
if (hour == HOUR && minute == MINUTE)
{
try
{
autoBackUp.createAutoBackUp(hour, minute);
} catch (SchedulerException ex)
{
ex.printStackTrace();
}
} else
{
HomeFrame instance = HomeFrame.getInstance();
instance.setVisible(isDisplay);
}
}
break;
}
}
} else
{
HomeFrame instance = HomeFrame.getInstance();
instance.setVisible(isDisplay);
}
}
}
}
调度程序类
自动备份。java
public class AutoBackUp
{
Scheduler scheduler;
int dayHour;
int dayMinute;
public void createAutoBackUp(int hour, int minute) throws SchedulerException
{
scheduler = new StdSchedulerFactory().getScheduler();
JobKey backUpJobKey = new JobKey("backUpJob", "backUpGroup");
TriggerKey backUpTriggerKey = new TriggerKey("backUpTrigger", "backUpTriggerGroup");
boolean checkExists = scheduler.checkExists(backUpJobKey);
dayHour = hour;
dayMinute = minute;
scheduleJob(AutoBackupCreator.class, checkExists, backUpJobKey, backUpTriggerKey, dayHour, dayMinute);
}
private void scheduleJob(Class c, boolean checkExists, JobKey jobKey, TriggerKey triggerKey, int day_hour, int day_minute)
{
JobDetail jobDetail = null;
if (c.isInstance(new AutoBackupCreator()))
{
jobDetail = newJob(AutoBackupCreator.class).withIdentity(jobKey).build();
}
// Date providedDate = todayAt(day_hour, day_minute, 0);
// Date currentDate = new Date();
//
// System.out.println("Print Fourth Line");
//
// if (currentDate.before(providedDate))
// {
// System.out.println("todayAt() can be perfomed");
// } else
// {
// System.out.println("tomorrowAt() can be perfomed");
// }
Trigger trigger = newTrigger().withIdentity(triggerKey)
.withSchedule(simpleSchedule().withIntervalInHours(24).repeatForever())
.startAt((todayAt(day_hour, day_minute, 0))).build();
try
{
if (checkExists)
{
scheduler.start();
scheduler.rescheduleJob(triggerKey, trigger);
System.out.println("Job Re-scheduled");
} else
{
scheduler.start();
scheduler.scheduleJob(jobDetail, trigger);
System.out.println("Job Scheduled");
}
} catch (SchedulerException ex)
{
ex.printStackTrace();
}
}
}
下一节课是我的职业课
自动备份创建者。java
public class AutoBackupCreator implements Job
{
public static File temp;
@Override
public void execute(JobExecutionContext jec) throws JobExecutionException
{
runAutomatedBackUp();
}
public void runAutomatedBackUp()
{
}
public Timestamp getCurrentTimestamp()
{
Date date = new Date();
Timestamp timestamp = new Timestamp(date.getTime());
return timestamp;
}
}
您对如何正确运行应用程序有何想法
多谢各位
共 (0) 个答案