我有一个程序,可以将文件路径和对应的参数插入到表中。之后,我有另一个名为
但是,我希望这个函数
我考虑使用一个计时器类,但不太确定如何实现配置。我的想法是创建一个计时器函数,它将调用
这个类应该像这样:
do_Scan()
的函数,它会扫描该表并进行一些处理和索引。但是,我希望这个函数
do_Scan()
在特定时间间隔内运行,比如每N分钟就调用此函数。这个N肯定是可配置的。我考虑使用一个计时器类,但不太确定如何实现配置。我的想法是创建一个计时器函数,它将调用
do_Scan()
方法。这个类应该像这样:
public void schedule(TimerTask task,long delay,long period){
}
我的主要方法:
public static void main(String[] args) throws Exception {
Indexing test= new Indexing();
java.sql.Timestamp date = new java.sql.Timestamp(new java.util.Date().getTime());
// Exception e=e.printStackTrace();
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a file path: ");
System.out.flush();
String filename = scanner.nextLine();
File file = new File(filename);
if(file.exists() && !file.isDirectory()) {
test.index_request(filename,"Active",date,date,"");
}else{
test.index_request(filename,"Error",date,date,"Some errorCode");
}
// Call schedule() function
}}
如何设置 Timer 类使其在一定时间间隔内无限运行?