I have a program where I am able to insert a filepath and it's corresponding parameters to a table.
After that, I have another function called do_Scan()
that scans the table and do some processing and indexing to it.
However, I want this function do_Scan()
to be run at certain intervals, say every N minutes then it will call this function. The N is definitely configurable.
I was thinking of using a timer class but not quite sure how to implement the configuration. The idea is I create a Timer function that will call the do_Scan
method.
The class should be something like this:
public void schedule(TimerTask task,long delay,long period){
}
My main method:
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
}}
How do I setup the Timer class so it runs indefinitely for certain interval?