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