0
我使用Cron安排在管理员给定的特定时间内将文件上载到服务器。我创建关于java,其中用户可以选择上载程序的执行时间,并提交所选的值的接口,一旦提交执行以下的方法:cron计划冻结
public class Reminder {
String minute;
//static int i=0;
String heur;
String substr=",";
String patterns;
List<String> list = null;
List<String> lines = new ArrayList<>();
Timer timer;
FTPUploadFileDemo up=new FTPUploadFileDemo();
public void start() throws IOException {
/************ Get the chosen values from the administrator saved in a CSV file *********************************************************/
BufferedReader reader;
try {
reader = new BufferedReader(new FileReader("C:/Users/BACKENDPC1/Desktop/timer.csv"));
String line = null;
while ((line = reader.readLine()) != null) {
lines.add(line);
}} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();}
/**********************create cron patterns *********************************************/
patterns="";
for(int i=0; i<lines.size();i++) {
heur=lines.get(i).substring(0, lines.get(i).indexOf(substr));
minute=lines.get(i).substring(lines.get(i).indexOf(substr) + substr.length());
System.out.println("Time selected is: "+heur+","+minute);
patterns=patterns+minute+" "+heur+" * * *|";
}
System.out.println(patterns);
// Creates the scheduler.
Scheduler scheduler = new Scheduler();
// Schedules the task, once every minute.
scheduler.schedule(patterns,new RemindTask());
scheduler.start();
try {
Thread.sleep(1L * 60L * 1000L);
} catch (InterruptedException e) {
System.out.println(e);
}
// Stops the scheduler.
scheduler.stop();
}
class RemindTask extends TimerTask {
public void run() {
up.Uplaod();
}
}
}
调度作品它运行,但每当我创建的用户界面冻结,我没有得到任何错误,程序继续运行,但我不能再使用该界面。任何人都可以帮助我。
在EDT _Don't_睡眠; _do_参见[* Swing中的并发*](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/)和[*如何使用Swing定时器*](http://docs.oracle.com/ JavaSE的/教程/ uiswing /杂项/ timer.html)。 – trashgod 2014-08-28 10:48:51