gpt4 book ai didi

java - 安排多次启动 Java 中的方法

转载 作者:行者123 更新时间:2023-12-01 12:36:36 25 4
gpt4 key购买 nike

我正在开发一个程序,用于在管理员指定的特定时间将文件上传到服务器,管理员输入多个值(小时、分钟)。

示例:

[Hours,Minutes]=  [2,12] [ 2,15],[ 5,20 ] 

我将这些值保存在 CSV 文件中。

  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();}

//Get the Date corresponding to 11:01:00 pm today.
Calendar calendar = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("HH");
Format formatter = new SimpleDateFormat("m");
Format sec=new SimpleDateFormat("s");

/*heur=getList().get(i).substring(0, getList().get(i).indexOf(substr));
minute=getList().get(i).substring(getList().get(i).indexOf(substr) + substr.length());
System.out.println("Time selected is: "+heur+","+minute);*/
while (i<lines.size()) {
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(sdf.format(calendar.getTime()));
System.out.println(Integer.parseInt(formatter.format(new Date())));
if(Integer.parseInt(sdf.format(calendar.getTime()))==Integer.parseInt(heur)&&(Integer.parseInt(formatter.format(new Date()))==Integer.parseInt(minute))){


System.out.println(Integer.parseInt(heur)+"H"+ Integer.parseInt(minute));

calendar.set(Calendar.HOUR_OF_DAY,Integer.parseInt(heur) );
calendar.set(Calendar.MINUTE, Integer.parseInt(minute));
calendar.set(Calendar.SECOND, 0);
Date time = calendar.getTime();

timer = new Timer();
timer.schedule(new RemindTask(), time);
i++;
}}
i=1;

start();


/* timer = new Timer();
timer.schedule(new RemindTask(), seconds*1000);*/
}

class RemindTask extends TimerTask {

public void run() {


up.Uplaod();

long start = new Date().getTime();
long end=0;
int numIndexed=0;
boolean cond=true;
end = new Date().getTime();
cond=false;

// System.out.println("Indexing " + numIndexed + " files took "
// + (end - start) + " milliseconds");

timer.cancel();
//Terminate the timer thread

}

我运行此方法来安排上传的执行。它工作了两次,之后我收到一个错误:

Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "Hours"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at Reminder.start(Reminder.java:64)
at Reminder.start(Reminder.java:80)
at csvFileUploadMulti$4.actionPerformed(csvFileUploadMulti.java:269)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$400(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

有人可以帮我吗?

最佳答案

不要重新发明轮子。试试cron .

关于java - 安排多次启动 Java 中的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25523585/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com